From bcc542d199b8199b4ab44df345284c04025061a6 Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Mon, 16 Nov 2026 14:55:13 +0000 Subject: [PATCH] Key each key-commits result by its place in the list, so a repeated commit keeps both measurements Naming the same commit twice, interleaved with the change, is how the runner's spread is measured in one run. The results were keyed by the entry, so the second measurement overwrote the first and the table showed the later one in both columns. A result is now keyed by its position, and a repeated commit's columns are marked (1), (2). With a stub dotnet that writes a different measurement per run and the list 842e8e951, 27aba15f0, 842e8e951, 27aba15f0: master's scripts give 300 400 300 400, this branch 100 200 300 400. Fixes https://github.com/asc-community/AngouriMath/issues/2488 Co-Authored-By: Claude Opus 5.5 --- Sources/Utils/benchmark_key_commits.sh | 33 ++++++++++++------- Sources/Utils/combine_key_commits.py | 44 +++++++++++++++++--------- 2 files changed, 50 insertions(+), 27 deletions(-) diff --git a/Sources/Utils/benchmark_key_commits.sh b/Sources/Utils/benchmark_key_commits.sh index 014c5053a..9b4f93210 100755 --- a/Sources/Utils/benchmark_key_commits.sh +++ b/Sources/Utils/benchmark_key_commits.sh @@ -48,7 +48,16 @@ mkdir -p "$results" commits=$(grep -vE '^\s*(#|$)' "$list") echo "measuring:"; echo "$commits" | sed 's/^/ /' +# A result is keyed by the entry's position in the list, not by the entry. Naming one commit +# twice, interleaved with the change, is how the runner's spread is measured in the same run, and +# keyed by name the second measurement overwrote the first: the 2.8.0 pair's table showed the +# later one in both columns, identical to the nanosecond, and the control silently was not there +# (https://github.com/asc-community/AngouriMath/issues/2488). combine_key_commits.py reads the +# same positions. +position=0 for commit in $commits; do + position=$((position + 1)) + key="$position" resolved=$(git -C "$repository" rev-parse --short "$commit" 2>/dev/null) # A branch name resolves to whatever this checkout's copy of it points at, which is not @@ -63,14 +72,14 @@ for commit in $commits; do fi if [ -z "$resolved" ]; then echo "=== $commit: not a commit in this repository" - echo "unresolved" > "$results/$commit.status" + echo "unresolved" > "$results/$key.status" continue fi echo "=== $commit ($resolved)" - tree="$work/$commit" + tree="$work/$key" rm -rf "$tree"; mkdir -p "$tree" - git -C "$repository" archive "$commit" | tar -x -C "$tree" || { echo "archive failed" > "$results/$commit.status"; continue; } + git -C "$repository" archive "$commit" | tar -x -C "$tree" || { echo "archive failed" > "$results/$key.status"; continue; } # The benchmark from HEAD, so every row is asked the same question. rm -rf "$tree/$benchmark" @@ -83,24 +92,24 @@ for commit in $commits; do # the row with it: MatchedRules and Patterns were internal until v2.3.0, and # Transformation.Rationalization did not exist until after v2.1.0. Passed for every row # including master, so what is compiled does not vary between columns. - if ! (cd "$tree/$benchmark" && dotnet build -c Release -p:InterVersionOnly=true > "$results/$commit.build.log" 2>&1); then - echo " did not build — see $results/$commit.build.log" - echo "did not build" > "$results/$commit.status" + if ! (cd "$tree/$benchmark" && dotnet build -c Release -p:InterVersionOnly=true > "$results/$key.build.log" 2>&1); then + echo " did not build — see $results/$key.build.log" + echo "did not build" > "$results/$key.status" continue fi - if ! (cd "$tree/$benchmark" && dotnet run -c Release --no-build CommonFunctionsInterVersion > "$results/$commit.run.log" 2>&1); then - echo " did not run — see $results/$commit.run.log" - echo "did not run" > "$results/$commit.status" + if ! (cd "$tree/$benchmark" && dotnet run -c Release --no-build CommonFunctionsInterVersion > "$results/$key.run.log" 2>&1); then + echo " did not run — see $results/$key.run.log" + echo "did not run" > "$results/$key.status" continue fi measured="$tree/$benchmark/benchmark_results.csv/measured-CommonFunctionsInterVersion.json" if [ -f "$measured" ]; then - cp "$measured" "$results/$commit.json" - echo "measured $resolved" > "$results/$commit.status" + cp "$measured" "$results/$key.json" + echo "measured $resolved" > "$results/$key.status" echo " measured" else - echo "ran but wrote nothing" > "$results/$commit.status" + echo "ran but wrote nothing" > "$results/$key.status" echo " ran but wrote no results file" fi done diff --git a/Sources/Utils/combine_key_commits.py b/Sources/Utils/combine_key_commits.py index d205a9c53..ef1c8d6c9 100644 --- a/Sources/Utils/combine_key_commits.py +++ b/Sources/Utils/combine_key_commits.py @@ -26,13 +26,13 @@ def read_list(path): if line.strip() and not line.strip().startswith("#")] -def read_results(directory, commit): - status_path = os.path.join(directory, commit + ".status") +def read_results(directory, key): + status_path = os.path.join(directory, key + ".status") status = "not attempted" if os.path.exists(status_path): with open(status_path) as handle: status = handle.read().strip() - measured_path = os.path.join(directory, commit + ".json") + measured_path = os.path.join(directory, key + ".json") measured = None if os.path.exists(measured_path): with open(measured_path) as handle: @@ -70,14 +70,26 @@ def column(measured, benchmark, field): return None if value is None else float(value) -def table(handle, commits, results, benchmarks, field, unit, heading, note): +def labels_of(commits): + """A column heading per entry. A commit named more than once is a column per occurrence, + marked `(2)`, `(3)`, so a control measured twice in one run reads as two measurements.""" + total = {commit: commits.count(commit) for commit in commits} + seen = {} + labels = [] + for commit in commits: + seen[commit] = seen.get(commit, 0) + 1 + labels.append(commit if total[commit] == 1 else "%s (%d)" % (commit, seen[commit])) + return labels + + +def table(handle, labels, results, benchmarks, field, unit, heading, note): handle.write("\n### %s\n\n%s\n\n" % (heading, note)) - handle.write("| benchmark | " + " | ".join(commits) + " |\n") - handle.write("|---" * (len(commits) + 1) + "|\n") + handle.write("| benchmark | " + " | ".join(labels) + " |\n") + handle.write("|---" * (len(labels) + 1) + "|\n") for benchmark in benchmarks: cells = [] - for commit in commits: - value = column(results[commit][1], benchmark, field) + for position in range(len(labels)): + value = column(results[position][1], benchmark, field) cells.append("—" if value is None else "{:,.0f}".format(value)) handle.write("| `%s` | %s |\n" % (benchmark, " | ".join(cells))) handle.write("\nIn %s. A dash is a commit this benchmark has no figure for.\n" % unit) @@ -91,11 +103,13 @@ def main(): list_path, results_directory, output = sys.argv[1:4] commits = read_list(list_path) - results = {commit: read_results(results_directory, commit) for commit in commits} + labels = labels_of(commits) + # Keyed by position, as benchmark_key_commits.sh writes them: entry 1 is `1.json`. + results = [read_results(results_directory, str(position + 1)) + for position in range(len(commits))] benchmarks = [] - for commit in commits: - measured = results[commit][1] + for measured in (result[1] for result in results): if measured: for name in measured: if name not in benchmarks: @@ -109,19 +123,19 @@ def main(): "differs, which is what makes the columns comparable.\n\n") handle.write("| commit | outcome |\n|---|---|\n") - for commit in commits: - handle.write("| `%s` | %s |\n" % (commit, results[commit][0])) + for label, result in zip(labels, results): + handle.write("| `%s` | %s |\n" % (label, result[0])) if not benchmarks: handle.write("\nNothing was measured, so there is no table to draw.\n") return 0 - table(handle, commits, results, benchmarks, "allocatedBytes", "bytes allocated", + table(handle, labels, results, benchmarks, "allocatedBytes", "bytes allocated", "Allocation", "**This is the one to read.** Allocation is deterministic — the same commit " "measured twice gives the same bytes — so a difference between two columns is a " "difference in the code rather than in the machine.") - table(handle, commits, results, benchmarks, "meanNanoseconds", "nanoseconds", + table(handle, labels, results, benchmarks, "meanNanoseconds", "nanoseconds", "Time", "Reported rather than relied on. On a shared runner this project has seen the " "same unchanged commit come back 30-57% apart, while its allocation over the same "