From 0dcbfeb9252ec3e367c131df0b8f09e07c3b7f7e Mon Sep 17 00:00:00 2001 From: Thomas Wouters Date: Fri, 4 Apr 2025 00:26:18 +0200 Subject: [PATCH 1/4] Add support for passing --same-loops to pyperformance for regular runs (not just pystats) by setting the PYPERFORMANCE_LOOPS_FILE environment variable. --- bench_runner/scripts/run_benchmarks.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/bench_runner/scripts/run_benchmarks.py b/bench_runner/scripts/run_benchmarks.py index d677b8be..38ed08c1 100644 --- a/bench_runner/scripts/run_benchmarks.py +++ b/bench_runner/scripts/run_benchmarks.py @@ -34,6 +34,7 @@ ) # Environment variables that control the execution of CPython ENV_VARS = ["PYTHON_JIT", "PYPERF_PERF_RECORD_EXTRA_OPTS"] +LOOPS_FILE_ENV_VAR = "PYPERFORMANCE_LOOPS_FILE" class NoBenchmarkError(Exception): @@ -82,6 +83,10 @@ def run_benchmarks( if extra_args is None: extra_args = [] + if (loops_file := os.environ.get(LOOPS_FILE_ENV_VAR)): + extra_args.append("--same-loops") + extra_args.append(loops_file) + args = [ sys.executable, "-m", @@ -130,7 +135,12 @@ def collect_pystats( all_benchmarks = get_benchmark_names(benchmarks) - extra_args = ["--same-loops", "loops.json", "--hook", "pystats"] + # Default to loops.json if not explicitly set, like before the + # environment variable was added. + if LOOPS_FILE_ENV_VAR not in os.environ: + os.environ[LOOPS_FILE_ENV_VAR] = "loops.json" + + extra_args = ["--hook", "pystats"] if flags is None: flags = [] From 8e44d0a07f477b3e1823c27a712cbc4f71540a7c Mon Sep 17 00:00:00 2001 From: Thomas Wouters Date: Sat, 5 Apr 2025 10:51:22 +0200 Subject: [PATCH 2/4] Reformat. --- bench_runner/scripts/run_benchmarks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bench_runner/scripts/run_benchmarks.py b/bench_runner/scripts/run_benchmarks.py index 38ed08c1..6eeb650d 100644 --- a/bench_runner/scripts/run_benchmarks.py +++ b/bench_runner/scripts/run_benchmarks.py @@ -83,7 +83,7 @@ def run_benchmarks( if extra_args is None: extra_args = [] - if (loops_file := os.environ.get(LOOPS_FILE_ENV_VAR)): + if loops_file := os.environ.get(LOOPS_FILE_ENV_VAR): extra_args.append("--same-loops") extra_args.append(loops_file) From 9144dc1cdf460266af63a5e471c68539f2345207 Mon Sep 17 00:00:00 2001 From: Thomas Wouters Date: Sat, 5 Apr 2025 10:56:59 +0200 Subject: [PATCH 3/4] Fix type annotation. --- bench_runner/scripts/run_benchmarks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bench_runner/scripts/run_benchmarks.py b/bench_runner/scripts/run_benchmarks.py index 6eeb650d..d0e959bd 100644 --- a/bench_runner/scripts/run_benchmarks.py +++ b/bench_runner/scripts/run_benchmarks.py @@ -67,7 +67,7 @@ def run_benchmarks( benchmarks: str, /, test_mode: bool = False, - extra_args: Iterable[str] | None = None, + extra_args: list[str] | None = None, ) -> None: if benchmarks.strip() == "": benchmarks = "all" From 18aec6e44fa382bfb4a6d68bfdc1fc98aa1f7cf6 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Mon, 7 Apr 2025 09:04:59 -0400 Subject: [PATCH 4/4] Remove trailing whitespace in run_benchmarks.py --- bench_runner/scripts/run_benchmarks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bench_runner/scripts/run_benchmarks.py b/bench_runner/scripts/run_benchmarks.py index 6e1e9077..01a3ad66 100644 --- a/bench_runner/scripts/run_benchmarks.py +++ b/bench_runner/scripts/run_benchmarks.py @@ -86,7 +86,7 @@ def run_benchmarks( if loops_file := os.environ.get(LOOPS_FILE_ENV_VAR): extra_args.append("--same-loops") extra_args.append(loops_file) - + if affinity := os.environ.get("CPU_AFFINITY"): extra_args.append(f"--affinity={affinity}")