Skip to content

Commit 5cb5c7b

Browse files
CI: Add a --seq flag to run benchmarks sequentially (#267)
This can be useful to benchmark runtime -- currently the runtime reported by the CI isn't too trustworthy because it runs all the benchmarks in parallel which can lead to nondeterministic results. If we in the future make a change that we expect to improve runtime, we should use the `--seq` flag to test it. Co-authored-by: Olexandr Balyk <[email protected]>
1 parent 7095562 commit 5cb5c7b

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

utils/run_benchmarks.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ def run_all_benchmarks(
272272
skip_csv=False,
273273
skip_main=False,
274274
skip_regression=False,
275-
verbose=False,
275+
seq: bool = False,
276+
verbose: bool = False,
276277
debug: bool = False,
277278
):
278279
logger.info("Running benchmarks", end="", flush=True)
@@ -287,7 +288,7 @@ def run_all_benchmarks(
287288
debug=debug,
288289
)
289290

290-
if debug:
291+
if debug or seq:
291292
# bypass process pool and call benchmarks directly if --debug is set.
292293
results = [run_a_benchmark(b) for b in benchmarks]
293294
else:
@@ -353,8 +354,11 @@ def run_all_benchmarks(
353354
debug=debug,
354355
)
355356

356-
with ProcessPoolExecutor(max_workers) as executor:
357-
results_main = list(executor.map(run_a_benchmark, benchmarks))
357+
if debug or seq:
358+
results_main = [run_a_benchmark(b) for b in benchmarks]
359+
else:
360+
with ProcessPoolExecutor(max_workers) as executor:
361+
results_main = list(executor.map(run_a_benchmark, benchmarks))
358362

359363
# Print table with combined results to make comparison easier
360364
trunc = lambda s: s[:10] + "\u2026" if len(s) > 10 else s # noqa
@@ -469,6 +473,12 @@ def run_all_benchmarks(
469473
default=False,
470474
help="Skip regression testing against main branch",
471475
)
476+
args_parser.add_argument(
477+
"--seq",
478+
action="store_true",
479+
default=False,
480+
help="Run benchmarks sequentially, instead of in parallel",
481+
)
472482
args_parser.add_argument(
473483
"--verbose",
474484
action="store_true",
@@ -523,6 +533,7 @@ def run_all_benchmarks(
523533
skip_csv=args.skip_csv,
524534
skip_main=args.skip_main,
525535
skip_regression=args.skip_regression,
536+
seq=args.seq,
526537
verbose=args.verbose,
527538
debug=args.debug,
528539
)

0 commit comments

Comments
 (0)