Skip to content

Commit b0185f3

Browse files
author
whitequark
committedJul 29, 2015
Add profiling to the performance testbench.
1 parent d7f9af4 commit b0185f3

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed
 

Diff for: ‎artiq/compiler/testbench/perf.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import sys, os, time
1+
import sys, os, time, cProfile as profile, pstats
22
from pythonparser import diagnostic
33
from .. import Module
44
from ..targets import OR1KTarget
@@ -21,6 +21,9 @@ def process_diagnostic(diag):
2121
for filename in sys.argv[1:]]
2222

2323
def benchmark(f, name):
24+
profiler = profile.Profile()
25+
profiler.enable()
26+
2427
start = time.perf_counter()
2528
end = 0
2629
runs = 0
@@ -29,9 +32,14 @@ def benchmark(f, name):
2932
runs += 1
3033
end = time.perf_counter()
3134

35+
profiler.create_stats()
36+
3237
print("{} {} runs: {:.2f}s, {:.2f}ms/run".format(
3338
runs, name, end - start, (end - start) / runs * 1000))
3439

40+
stats = pstats.Stats(profiler)
41+
stats.strip_dirs().sort_stats('time').print_stats(10)
42+
3543
sources = []
3644
for filename in sys.argv[1:]:
3745
with open(filename) as f:

0 commit comments

Comments
 (0)
Please sign in to comment.