Skip to content

Commit 56dfad1

Browse files
committed
Don't compute required_nprocesses unless necessary
1 parent a685a14 commit 56dfad1

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

pyperf/_cli.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,7 @@ def format_checks(bench, lines=None, check_too_many_processes=False):
412412
mean = bench.mean()
413413
warnings = []
414414
warn = warnings.append
415-
416-
required_nprocesses = bench.required_nprocesses()
415+
required_nprocesses = None
417416

418417
# Display a warning if the standard deviation is greater than 10%
419418
# of the mean
@@ -425,6 +424,7 @@ def format_checks(bench, lines=None, check_too_many_processes=False):
425424
% (bench.format_value(stdev), percent, bench.format_value(mean)))
426425
else:
427426
# display a warning if the number of samples isn't enough to get a stable result
427+
required_nprocesses = bench.required_nprocesses()
428428
if (
429429
required_nprocesses is not None and
430430
required_nprocesses > len(bench._runs)
@@ -466,16 +466,18 @@ def format_checks(bench, lines=None, check_too_many_processes=False):
466466
lines.append("Use pyperf stats, pyperf dump and pyperf hist to analyze results.")
467467
lines.append("Use --quiet option to hide these warnings.")
468468

469-
if (
470-
check_too_many_processes and
471-
required_nprocesses is not None and
472-
required_nprocesses < len(bench._runs) * 0.75
473-
):
474-
lines.append("Benchmark was run more times than necessary to get a stable result.")
475-
lines.append(
476-
"Consider passing processes=%d to the Runner constructor to save time." %
477-
required_nprocesses
478-
)
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+
)
479481

480482
# Warn if nohz_full+intel_pstate combo if found in cpu_config metadata
481483
for run in bench._runs:

0 commit comments

Comments
 (0)