From b0185f3917c9fd7911a2c1fd944f349c32b0df22 Mon Sep 17 00:00:00 2001 From: whitequark Date: Wed, 29 Jul 2015 22:23:22 +0300 Subject: [PATCH] Add profiling to the performance testbench. --- artiq/compiler/testbench/perf.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/artiq/compiler/testbench/perf.py b/artiq/compiler/testbench/perf.py index 7b0b81487..c24946fb6 100644 --- a/artiq/compiler/testbench/perf.py +++ b/artiq/compiler/testbench/perf.py @@ -1,4 +1,4 @@ -import sys, os, time +import sys, os, time, cProfile as profile, pstats from pythonparser import diagnostic from .. import Module from ..targets import OR1KTarget @@ -21,6 +21,9 @@ def main(): for filename in sys.argv[1:]] def benchmark(f, name): + profiler = profile.Profile() + profiler.enable() + start = time.perf_counter() end = 0 runs = 0 @@ -29,9 +32,14 @@ def main(): runs += 1 end = time.perf_counter() + profiler.create_stats() + print("{} {} runs: {:.2f}s, {:.2f}ms/run".format( runs, name, end - start, (end - start) / runs * 1000)) + stats = pstats.Stats(profiler) + stats.strip_dirs().sort_stats('time').print_stats(10) + sources = [] for filename in sys.argv[1:]: with open(filename) as f: