Skip to content

Commit 2096151

Browse files
committed
[benchmark] BenchmarkDoctor: Lower runtime limit
Warn about runtimes under 20 μs and flag 0 μs runtimes as errors.
1 parent 8a8a3ad commit 2096151

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

benchmark/scripts/Benchmark_Driver

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,19 @@ class BenchmarkDoctor(object):
435435
"Decrease the workload of '%s' by a factor of %d (%d), to be "
436436
"less than %d μs.", name, factor(2), factor(10), threshold)
437437

438+
threshold = 20
439+
if runtime < threshold:
440+
log = (BenchmarkDoctor.log_runtime.error if runtime == 0 else
441+
BenchmarkDoctor.log_runtime.warning)
442+
log("'%s' execution took %d μs.", name, runtime)
443+
444+
BenchmarkDoctor.log_runtime.info(
445+
"Ensure the workload of '%s' has a properly measurable size"
446+
" (runtime > %d μs) and is not eliminated by the compiler (use"
447+
" `blackHole` function if necessary)." if runtime == 0 else
448+
"Increase the workload of '%s' to be more than %d μs.",
449+
name, threshold)
450+
438451
@staticmethod
439452
def _setup_overhead(measurements):
440453
select = BenchmarkDoctor._select

benchmark/scripts/test_Benchmark_Driver.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ def test_benchmark_name_is_at_most_40_chars_long(self):
667667
self.logs['info'])
668668

669669
def test_benchmark_runtime_range(self):
670-
"""Optimized benchmark should run in less then 1000 μs.
670+
"""Optimized benchmark should have runtime between 20 μs and 1000 μs.
671671
672672
Even on calm machine, benchmark with runtime of 2500 μs has 1:4 chance
673673
of being interrupted in the middle of measurement due to elapsed 10 ms
@@ -687,6 +687,8 @@ def measurements(name, runtime):
687687

688688
with captured_output() as (out, _):
689689
doctor = BenchmarkDoctor(self.args, BenchmarkDriverMock([]))
690+
doctor.analyze(measurements('Sylph', 0))
691+
doctor.analyze(measurements('Unicorn', 3))
690692
doctor.analyze(measurements('Cheetah', 200))
691693
doctor.analyze(measurements('Hare', 1001))
692694
doctor.analyze(measurements('Tortoise', 500000))
@@ -697,6 +699,18 @@ def measurements(name, runtime):
697699

698700
self.assertIn('runtime: ', output)
699701
self.assertNotIn('Cheetah', output)
702+
self.assert_contains(["'Sylph' execution took 0 μs."],
703+
self.logs['error'])
704+
self.assert_contains(
705+
["Ensure the workload of 'Sylph' has a properly measurable size"
706+
" (runtime > 20 μs) and is not eliminated by the compiler (use "
707+
"`blackHole` function if necessary)."],
708+
self.logs['info'])
709+
self.assert_contains(["'Unicorn' execution took 3 μs."],
710+
self.logs['warning'])
711+
self.assert_contains(
712+
["Increase the workload of 'Unicorn' to be more than 20 μs."],
713+
self.logs['info'])
700714
self.assert_contains(["'Hare' execution took at least 1001 μs."],
701715
self.logs['warning'])
702716
self.assert_contains(

0 commit comments

Comments
 (0)