@@ -400,7 +400,7 @@ def value_bucket(value):
400400 return lines
401401
402402
403- def format_checks (bench , lines = None ):
403+ def format_checks (bench , lines = None , check_too_many_processes = False ):
404404 if lines is None :
405405 lines = []
406406
@@ -412,6 +412,7 @@ def format_checks(bench, lines=None):
412412 mean = bench .mean ()
413413 warnings = []
414414 warn = warnings .append
415+ required_nprocesses = None
415416
416417 # Display a warning if the standard deviation is greater than 10%
417418 # of the mean
@@ -421,6 +422,14 @@ def format_checks(bench, lines=None):
421422 if percent >= 10.0 :
422423 warn ("the standard deviation (%s) is %.0f%% of the mean (%s)"
423424 % (bench .format_value (stdev ), percent , bench .format_value (mean )))
425+ else :
426+ # display a warning if the number of samples isn't enough to get a stable result
427+ required_nprocesses = bench .required_nprocesses ()
428+ if (
429+ required_nprocesses is not None and
430+ required_nprocesses > len (bench ._runs )
431+ ):
432+ warn ("Not enough samples to get a stable result (95% certainly of less than 1% variation)" )
424433
425434 # Minimum and maximum, detect obvious outliers
426435 for minimum , value in (
@@ -457,6 +466,19 @@ def format_checks(bench, lines=None):
457466 lines .append ("Use pyperf stats, pyperf dump and pyperf hist to analyze results." )
458467 lines .append ("Use --quiet option to hide these warnings." )
459468
469+ if check_too_many_processes :
470+ if required_nprocesses is None :
471+ required_nprocesses = bench .required_nprocesses ()
472+ if (
473+ required_nprocesses is not None and
474+ required_nprocesses < len (bench ._runs ) * 0.75
475+ ):
476+ lines .append ("Benchmark was run more times than necessary to get a stable result." )
477+ lines .append (
478+ "Consider passing processes=%d to the Runner constructor to save time." %
479+ required_nprocesses
480+ )
481+
460482 # Warn if nohz_full+intel_pstate combo if found in cpu_config metadata
461483 for run in bench ._runs :
462484 cpu_config = run ._metadata .get ('cpu_config' )
@@ -549,7 +571,7 @@ def format_result(bench):
549571
550572def format_benchmark (bench , checks = True , metadata = False ,
551573 dump = False , stats = False , hist = False , show_name = False ,
552- result = True , display_runs_args = None ):
574+ result = True , display_runs_args = None , only_checks = False ):
553575 lines = []
554576
555577 if metadata :
@@ -568,7 +590,7 @@ def format_benchmark(bench, checks=True, metadata=False,
568590 format_stats (bench , lines = lines )
569591
570592 if checks :
571- format_checks (bench , lines = lines )
593+ format_checks (bench , lines = lines , check_too_many_processes = only_checks )
572594
573595 if result :
574596 empty_line (lines )
0 commit comments