@@ -548,13 +548,18 @@ def test_benchmark_name_is_at_most_40_chars_long(self):
548
548
self .logs ['info' ])
549
549
550
550
def test_benchmark_runtime_range (self ):
551
- """Optimized benchmark should run in less then 2500 μs.
552
-
553
- With runtimes less than 2500 μs there is better than 1:4 chance of
554
- being interrupted in the middle of measurement due to elapsed 10 ms
555
- quantum used by macos scheduler.
556
-
557
- Warn about longer runtime. Runtimes over half a second are an error.
551
+ """Optimized benchmark should run in less then 1000 μs.
552
+
553
+ Even on calm machine, benchmark with runtime of 2500 μs has 1:4 chance
554
+ of being interrupted in the middle of measurement due to elapsed 10 ms
555
+ quantum used by macos scheduler. Linux scheduler's quantum is 6ms.
556
+ Driver yielding the process before the 10ms quantum elapses helped
557
+ a lot, but benchmarks with runtimes under 1ms usually exhibit a strong
558
+ mode which is best for accurate performance charaterization.
559
+ To minimize the number of involuntary context switches that corrupt our
560
+ measurements, we should strive to stay in the microbenchmark range.
561
+
562
+ Warn about longer runtime. Runtimes over 10ms are an error.
558
563
"""
559
564
def measurements (name , runtime ):
560
565
return {'name' : name ,
@@ -564,7 +569,7 @@ def measurements(name, runtime):
564
569
with captured_output () as (out , _ ):
565
570
doctor = BenchmarkDoctor (self .args , BenchmarkDriverMock ([]))
566
571
doctor .analyze (measurements ('Cheetah' , 200 ))
567
- doctor .analyze (measurements ('Hare' , 2501 ))
572
+ doctor .analyze (measurements ('Hare' , 1001 ))
568
573
doctor .analyze (measurements ('Tortoise' , 500000 ))
569
574
doctor .analyze ({'name' : 'OverheadTurtle' ,
570
575
'OverheadTurtle O i1a' : _PTR (min = 800000 ),
@@ -573,17 +578,17 @@ def measurements(name, runtime):
573
578
574
579
self .assertIn ('runtime: ' , output )
575
580
self .assertNotIn ('Cheetah' , output )
576
- self .assert_contains (["'Hare' execution took at least 2501 μs." ],
581
+ self .assert_contains (["'Hare' execution took at least 1001 μs." ],
577
582
self .logs ['warning' ])
578
583
self .assert_contains (
579
- ["Decrease the workload of 'Hare' by a factor of 2, "
580
- "to be less than 2500 μs." ], self .logs ['info' ])
584
+ ["Decrease the workload of 'Hare' by a factor of 2 (10) , "
585
+ "to be less than 1000 μs." ], self .logs ['info' ])
581
586
self .assert_contains (
582
587
["'Tortoise' execution took at least 500000 μs." ],
583
588
self .logs ['error' ])
584
589
self .assert_contains (
585
- ["Decrease the workload of 'Tortoise' by a factor of 256 , "
586
- "to be less than 2500 μs." ], self .logs ['info' ])
590
+ ["Decrease the workload of 'Tortoise' by a factor of 512 (1000) , "
591
+ "to be less than 1000 μs." ], self .logs ['info' ])
587
592
self .assert_contains (
588
593
["'OverheadTurtle' execution took at least 600000 μs"
589
594
" (excluding the setup overhead)." ],
0 commit comments