Skip to content

Commit 1165aeb

Browse files
committed
[hotfix] add stats at end of harness execution (best / worst / avg duration)
PullRequest: graalpython/254
2 parents 746982a + 8646315 commit 1165aeb

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

graalpython/benchmarks/src/harness.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ def run(self):
157157
print("### start benchmark ... ")
158158

159159
bench_func = self._get_attr(ATTR_BENCHMARK)
160+
durations = []
160161
if bench_func and hasattr(bench_func, '__call__'):
161162
if self.warmup:
162163
print("### warming up for %s iterations ... " % self.warmup)
@@ -166,17 +167,23 @@ def run(self):
166167
for iteration in range(self.iterations):
167168
start = time()
168169
bench_func(*args)
169-
duration = "%.3f" % (time() - start)
170+
duration = time() - start
171+
durations.append(duration)
172+
duration_str = "%.3f" % duration
170173
if self._run_once:
171-
print("@@@ name=%s, duration=%s" % (self.bench_module.__name__, duration))
174+
print("@@@ name=%s, duration=%s" % (self.bench_module.__name__, duration_str))
172175
else:
173-
print("### iteration=%s, name=%s, duration=%s" % (iteration, self.bench_module.__name__, duration))
176+
print("### iteration=%s, name=%s, duration=%s" % (iteration, self.bench_module.__name__, duration_str))
174177

175178
print(_HRULE)
176179
print("### teardown ... ")
177180
self._call_attr(ATTR_TEARDOWN)
178181
print("### benchmark complete")
179182
print(_HRULE)
183+
print("### BEST duration: %.3f s" % min(durations))
184+
print("### WORST duration: %.3f s" % max(durations))
185+
print("### AVG duration: %.3f" % (sum(durations) / len(durations)))
186+
print(_HRULE)
180187

181188

182189
def run_benchmark(args):

0 commit comments

Comments
 (0)