Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit bcc1ea5

Browse files
committed
profile vm
1 parent 51ef2d1 commit bcc1ea5

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

ethereum/tests/profile_vm.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import json
2+
import os
3+
import sys
4+
import ethereum.testutils as testutils
5+
import cProfile
6+
import pstats
7+
import StringIO
8+
import time
9+
from ethereum.utils import sha3_call_counter, sha3
10+
from ethereum.slogging import get_logger, configure_logging, get_configuration
11+
logger = get_logger()
12+
import sys
13+
14+
15+
def do_test_vm(filename, testname=None, testdata=None, limit=99999999, profiler=None):
16+
logger.debug('running test:%r in %r' % (testname, filename))
17+
testutils.run_vm_test(testutils.fixture_to_bytes(testdata), testutils.VERIFY, profiler=profiler)
18+
19+
if __name__ == '__main__':
20+
num = 5000
21+
print 'loading tests'
22+
fixtures = testutils.get_tests_from_file_or_dir(
23+
os.path.join(testutils.fixture_path, 'VMTests'))
24+
25+
def run(profiler=None):
26+
print 'running'
27+
i = 0
28+
seen = b''
29+
for filename, tests in fixtures.items():
30+
for testname, testdata in tests.items():
31+
if i == num:
32+
break
33+
do_test_vm(filename, testname, testdata, profiler=profiler)
34+
seen += str(testname)
35+
i += 1
36+
print 'ran %d tests' % i
37+
print 'test key', sha3(seen).encode('hex')
38+
39+
if len(sys.argv) == 2:
40+
pr = cProfile.Profile()
41+
run(pr)
42+
s = StringIO.StringIO()
43+
sortby = 'tottime'
44+
ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
45+
ps.print_stats(50)
46+
print s.getvalue()
47+
else:
48+
st = time.time()
49+
run()
50+
print
51+
print 'took total', time.time() - st
52+
print 'took w/o sha3', time.time() - st - sha3_call_counter[3]

0 commit comments

Comments
 (0)