Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.

Commit 1bea0ac

Browse files
authoredOct 19, 2016
Merge pull request #3358 from chfast/exp-tests
EXP tests
2 parents a654380 + 6593b1a commit 1bea0ac

File tree

7 files changed

+288
-21
lines changed

7 files changed

+288
-21
lines changed
 

‎test/Stats.cpp

+24-4
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ void Stats::testStarted(std::string const& _name)
4343
m_tp = clock::now();
4444
}
4545

46-
void Stats::testFinished()
46+
void Stats::testFinished(int64_t _gasUsed)
4747
{
48-
m_stats.push_back({clock::now() - m_tp, m_currentSuite + "/" + m_currentTest});
48+
m_stats.push_back({clock::now() - m_tp, _gasUsed, m_currentSuite + "/" + m_currentTest});
4949
}
5050

5151
std::ostream& operator<<(std::ostream& out, Stats::clock::duration const& d)
@@ -78,15 +78,35 @@ Stats::~Stats()
7878
if (Options::get().statsOutFile == "out")
7979
{
8080
for (auto&& s: m_stats)
81-
out << " " << std::setw(40) << std::left << s.name.substr(0, 40) << s.duration << " \n";
81+
{
82+
auto usecs = std::chrono::duration_cast<std::chrono::microseconds>(s.duration).count();
83+
out << " " << std::setw(40) << std::left << s.name.substr(0, 40) << s.duration;
84+
if (s.gasUsed >= 0)
85+
{
86+
auto gasRate = uint64_t(double(s.gasUsed) * 1000 / usecs);
87+
out << "\t" << std::setw(10) << std::right << gasRate << " gas/ms\n";
88+
}
89+
else
90+
out << "\tOOG\n";
91+
}
8292
out << "\n";
8393
}
8494
else if (!Options::get().statsOutFile.empty())
8595
{
8696
// Output stats to file
8797
std::ofstream file{Options::get().statsOutFile};
8898
for (auto&& s: m_stats)
89-
file << s.name << "\t" << std::chrono::duration_cast<std::chrono::microseconds>(s.duration).count() << "\n";
99+
{
100+
auto usecs = std::chrono::duration_cast<std::chrono::microseconds>(s.duration).count();
101+
file << s.name << "\t" << usecs;
102+
if (s.gasUsed >= 0)
103+
{
104+
auto gasRate = s.gasUsed / usecs;
105+
file << "\t" << gasRate << " gas/us\n";
106+
}
107+
else
108+
file << "\tOOG\n";
109+
}
90110
}
91111

92112
out << " tot: " << tot << "\n"

‎test/Stats.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ class Stats: public Listener
3535
struct Item
3636
{
3737
clock::duration duration;
38-
std::string name;
38+
int64_t gasUsed;
39+
std::string name;
3940
};
4041

4142
static Stats& get();
@@ -44,7 +45,7 @@ class Stats: public Listener
4445

4546
void suiteStarted(std::string const& _name) override;
4647
void testStarted(std::string const& _name) override;
47-
void testFinished() override;
48+
void testFinished(int64_t _gasUsed) override;
4849

4950
private:
5051
clock::time_point m_tp;

‎test/TestHelper.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ void replaceLLLinState(json_spirit::mObject& _o)
248248
}
249249

250250
void ImportTest::importState(json_spirit::mObject const& _o, State& _state, AccountMaskMap& o_mask)
251-
{
251+
{
252252
//Compile LLL code of the test Fillers using external call to lllc
253253
json_spirit::mObject o = _o;
254254
replaceLLLinState(o);
@@ -323,7 +323,7 @@ void ImportTest::importTransaction (json_spirit::mObject const& _o, eth::Transac
323323
}
324324

325325
void ImportTest::importTransaction(json_spirit::mObject const& o_tr)
326-
{
326+
{
327327
importTransaction(o_tr, m_transaction);
328328
}
329329

@@ -372,7 +372,7 @@ int ImportTest::compareStates(State const& _stateExpect, State const& _statePost
372372
}
373373

374374
if (_statePost.addressInUse(a.first))
375-
{
375+
{
376376

377377
if (addressOptions.hasBalance())
378378
CHECK((_stateExpect.balance(a.first) == _statePost.balance(a.first)),
@@ -428,7 +428,7 @@ int ImportTest::exportTest(bytes const& _output)
428428
m_testObject.erase(m_testObject.find("expectOut"));
429429
}
430430

431-
// export logs
431+
// export logs
432432
m_testObject["logs"] = exportLog(m_logs);
433433

434434
// compare expected state with post state
@@ -600,7 +600,7 @@ LogEntries importLog(json_spirit::mArray& _a)
600600
LogEntries logEntries;
601601
for (auto const& l: _a)
602602
{
603-
json_spirit::mObject o = l.get_obj();
603+
json_spirit::mObject o = l.get_obj();
604604
BOOST_REQUIRE(o.count("address") > 0);
605605
BOOST_REQUIRE(o.count("topics") > 0);
606606
BOOST_REQUIRE(o.count("data") > 0);
@@ -836,7 +836,7 @@ RLPStream createRLPStreamFromTransactionFields(json_spirit::mObject const& _tObj
836836
}
837837

838838
Options::Options(int argc, char** argv)
839-
{
839+
{
840840
for (auto i = 0; i < argc; ++i)
841841
{
842842
auto arg = std::string{argv[i]};
@@ -1030,10 +1030,10 @@ void Listener::notifyTestStarted(std::string const& _name)
10301030
g_listener->testStarted(_name);
10311031
}
10321032

1033-
void Listener::notifyTestFinished()
1033+
void Listener::notifyTestFinished(int64_t _gasUsed)
10341034
{
10351035
if (g_listener)
1036-
g_listener->testFinished();
1036+
g_listener->testFinished(_gasUsed);
10371037
}
10381038

10391039
size_t TestOutputHelper::m_currTest = 0;
@@ -1062,12 +1062,12 @@ void TestOutputHelper::initTest(json_spirit::mValue& _v)
10621062
m_currentTestCaseName = boost::unit_test::framework::current_test_case().p_name;
10631063
std::cout << "Test Case \"" + m_currentTestCaseName + "\": " << std::endl;
10641064
m_maxTests = _v.get_obj().size();
1065-
m_currTest = 0;
1065+
m_currTest = 0;
10661066
}
10671067

10681068
bool TestOutputHelper::passTest(json_spirit::mObject& _o, std::string& _testName)
10691069
{
1070-
m_currTest++;
1070+
m_currTest++;
10711071
int m_testsPerProgs = std::max(1, (int)(m_maxTests / 4));
10721072
if (m_currTest % m_testsPerProgs == 0 || m_currTest == m_maxTests)
10731073
{

‎test/TestHelper.h

+7-5
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class ImportTest
133133
eth::State m_statePre;
134134
eth::State m_statePost;
135135
eth::EnvInfo m_envInfo;
136-
eth::Transaction m_transaction;
136+
eth::Transaction m_transaction;
137137
eth::LogEntries m_logs;
138138
eth::LogEntries m_logsExpected;
139139

@@ -245,7 +245,7 @@ class TestOutputHelper
245245
TestOutputHelper() { TestOutputHelper::initTest(); }
246246
static void initTest(int _maxTests = 1);
247247
static void initTest(json_spirit::mValue& _v);
248-
static bool passTest(json_spirit::mObject& _o, std::string& _testName);
248+
static bool passTest(json_spirit::mObject& _o, std::string& _testName);
249249
static void setMaxTests(int _count) { m_maxTests = _count; }
250250
static void setCurrentTestFileName(std::string _name) { m_currentTestFileName = _name; }
251251
static std::string const& testName() { return m_currentTestName; }
@@ -268,21 +268,23 @@ class Listener
268268

269269
virtual void suiteStarted(std::string const&) {}
270270
virtual void testStarted(std::string const& _name) = 0;
271-
virtual void testFinished() = 0;
271+
virtual void testFinished(int64_t _gasUsed) = 0;
272272

273273
static void registerListener(Listener& _listener);
274274
static void notifySuiteStarted(std::string const& _name);
275275
static void notifyTestStarted(std::string const& _name);
276-
static void notifyTestFinished();
276+
static void notifyTestFinished(int64_t _gasUsed);
277277

278278
/// Test started/finished notification RAII helper
279279
class ExecTimeGuard
280280
{
281+
int64_t m_gasUsed = -1;
281282
public:
282283
ExecTimeGuard(std::string const& _testName) { notifyTestStarted(_testName); }
283-
~ExecTimeGuard() { notifyTestFinished(); }
284+
~ExecTimeGuard() { notifyTestFinished(m_gasUsed); }
284285
ExecTimeGuard(ExecTimeGuard const&) = delete;
285286
ExecTimeGuard& operator=(ExecTimeGuard) = delete;
287+
void setGasUsed(int64_t _gas) { m_gasUsed = _gas; }
286288
};
287289
};
288290

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
pragma solidity ^0.4;
2+
3+
contract ExpPerformanceTester {
4+
5+
function testExp(int exponent, int seed, uint n) external returns (int) {
6+
int e = seed;
7+
for (uint i = 0; i < n; i += 1) {
8+
e = e ** exponent;
9+
}
10+
return e;
11+
}
12+
13+
function testExpUnroll16(int exponent, int seed, uint n) external returns (int) {
14+
int e = seed;
15+
for (uint i = 0; i < n; i += 16) {
16+
e = e ** exponent;
17+
e = e ** exponent;
18+
e = e ** exponent;
19+
e = e ** exponent;
20+
e = e ** exponent;
21+
e = e ** exponent;
22+
e = e ** exponent;
23+
e = e ** exponent;
24+
e = e ** exponent;
25+
e = e ** exponent;
26+
e = e ** exponent;
27+
e = e ** exponent;
28+
e = e ** exponent;
29+
e = e ** exponent;
30+
e = e ** exponent;
31+
e = e ** exponent;
32+
}
33+
return e;
34+
}
35+
36+
function testNop(int exponent, int seed, uint n) external returns (int) {
37+
for (uint i = 0; i < n; i += 1) {}
38+
return seed;
39+
}
40+
41+
function testNopUnroll16(int exponent, int seed, uint n) external returns (int) {
42+
for (uint i = 0; i < n; i += 16) {}
43+
return seed;
44+
}
45+
}

0 commit comments

Comments
 (0)