Skip to content

Commit 5cd49c2

Browse files
committed
Use ASV continuous for the branch mode.
1 parent 1ebf20e commit 5cd49c2

File tree

1 file changed

+40
-42
lines changed

1 file changed

+40
-42
lines changed

benchmarks/bm_runner.py

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
# Common ASV arguments for all run_types except `custom`.
2929
ASV_HARNESS = (
30-
"run {posargs} --attribute rounds=4 --interleave-rounds --strict "
30+
"{command} {posargs} --attribute rounds=4 --interleave-rounds --strict "
3131
"--show-stderr"
3232
)
3333

@@ -127,37 +127,6 @@ def _setup_common() -> None:
127127
echo("Setup complete.")
128128

129129

130-
def _asv_compare(*commits: str, overnight_mode: bool = False) -> None:
131-
"""Run through a list of commits comparing each one to the next."""
132-
commits = [commit[:8] for commit in commits]
133-
shifts_dir = BENCHMARKS_DIR / ".asv" / "performance-shifts"
134-
for i in range(len(commits) - 1):
135-
before = commits[i]
136-
after = commits[i + 1]
137-
asv_command = (
138-
f"compare {before} {after} --factor={COMPARE_FACTOR} --split"
139-
)
140-
_subprocess_run_asv(asv_command.split(" "))
141-
142-
if overnight_mode:
143-
# Record performance shifts.
144-
# Run the command again but limited to only showing performance
145-
# shifts.
146-
shifts = _subprocess_run_asv(
147-
[*asv_command.split(" "), "--only-changed"],
148-
capture_output=True,
149-
text=True,
150-
).stdout
151-
if shifts:
152-
# Write the shifts report to a file.
153-
# Dir is used by .github/workflows/benchmarks.yml,
154-
# but not cached - intended to be discarded after run.
155-
shifts_dir.mkdir(exist_ok=True, parents=True)
156-
shifts_path = (shifts_dir / after).with_suffix(".txt")
157-
with shifts_path.open("w") as shifts_file:
158-
shifts_file.write(shifts)
159-
160-
161130
class _SubParserGenerator(ABC):
162131
"""Convenience for holding all the necessary argparse info in 1 place."""
163132

@@ -225,7 +194,7 @@ def func(args: argparse.Namespace) -> None:
225194
_setup_common()
226195

227196
commit_range = f"{args.first_commit}^^.."
228-
asv_command = ASV_HARNESS.format(posargs=commit_range)
197+
asv_command = ASV_HARNESS.format(command="run", posargs=commit_range)
229198
_subprocess_run_asv([*asv_command.split(" "), *args.asv_args])
230199

231200
# git rev-list --first-parent is the command ASV uses.
@@ -234,6 +203,35 @@ def func(args: argparse.Namespace) -> None:
234203
git_command.split(" "), capture_output=True, text=True
235204
).stdout
236205
commit_list = commit_string.rstrip().split("\n")
206+
207+
# Run through the list of commits comparing each one to the next.
208+
commits = [commit[:8] for commit in commit_list]
209+
shifts_dir = BENCHMARKS_DIR / ".asv" / "performance-shifts"
210+
for i in range(len(commits) - 1):
211+
before = commits[i]
212+
after = commits[i + 1]
213+
asv_command = (
214+
f"compare {before} {after} --factor={COMPARE_FACTOR} --split"
215+
)
216+
_subprocess_run_asv(asv_command.split(" "))
217+
218+
# Record performance shifts.
219+
# Run the command again but limited to only showing performance
220+
# shifts.
221+
shifts = _subprocess_run_asv(
222+
[*asv_command.split(" "), "--only-changed"],
223+
capture_output=True,
224+
text=True,
225+
).stdout
226+
if shifts:
227+
# Write the shifts report to a file.
228+
# Dir is used by .github/workflows/benchmarks.yml,
229+
# but not cached - intended to be discarded after run.
230+
shifts_dir.mkdir(exist_ok=True, parents=True)
231+
shifts_path = (shifts_dir / after).with_suffix(".txt")
232+
with shifts_path.open("w") as shifts_file:
233+
shifts_file.write(shifts)
234+
237235
_asv_compare(*reversed(commit_list), overnight_mode=True)
238236

239237

@@ -269,14 +267,13 @@ def func(args: argparse.Namespace) -> None:
269267
git_command.split(" "), capture_output=True, text=True
270268
).stdout[:8]
271269

272-
with NamedTemporaryFile("w") as hashfile:
273-
hashfile.writelines([merge_base, "\n", "HEAD"])
274-
hashfile.flush()
275-
commit_range = f"HASHFILE:{hashfile.name}"
276-
asv_command = ASV_HARNESS.format(posargs=commit_range)
277-
_subprocess_run_asv([*asv_command.split(" "), *args.asv_args])
278-
279-
_asv_compare(merge_base, "HEAD")
270+
asv_command = (
271+
ASV_HARNESS.format(
272+
command="continuous", posargs=f"HEAD {merge_base}"
273+
)
274+
+ f" --factor={COMPARE_FACTOR}"
275+
)
276+
_subprocess_run_asv([*asv_command.split(" "), *args.asv_args])
280277

281278

282279
class _CSPerf(_SubParserGenerator, ABC):
@@ -324,7 +321,8 @@ def csperf(
324321
commit_range = "upstream/main^!"
325322

326323
asv_command = (
327-
ASV_HARNESS.format(posargs=commit_range) + f" --bench={run_type}"
324+
ASV_HARNESS.format(command="run", posargs=commit_range)
325+
+ f" --bench={run_type}"
328326
)
329327
# C/SPerf benchmarks are much bigger than the CI ones:
330328
# Don't fail the whole run if memory blows on 1 benchmark.

0 commit comments

Comments
 (0)