Skip to content

Commit 8aefdb3

Browse files
Key each key-commits result by its place in the list, so a repeated commit keeps both measurements (#2494)
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 842e8e9, 27aba15, 842e8e9, 27aba15: master's scripts give 300 400 300 400, this branch 100 200 300 400. Fixes #2488 Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent e996081 commit 8aefdb3

2 files changed

Lines changed: 50 additions & 27 deletions

File tree

‎Sources/Utils/benchmark_key_commits.sh‎

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,16 @@ mkdir -p "$results"
4848
commits=$(grep -vE '^\s*(#|$)' "$list")
4949
echo "measuring:"; echo "$commits" | sed 's/^/ /'
5050

51+
# A result is keyed by the entry's position in the list, not by the entry. Naming one commit
52+
# twice, interleaved with the change, is how the runner's spread is measured in the same run, and
53+
# keyed by name the second measurement overwrote the first: the 2.8.0 pair's table showed the
54+
# later one in both columns, identical to the nanosecond, and the control silently was not there
55+
# (https://github.com/asc-community/AngouriMath/issues/2488). combine_key_commits.py reads the
56+
# same positions.
57+
position=0
5158
for commit in $commits; do
59+
position=$((position + 1))
60+
key="$position"
5261
resolved=$(git -C "$repository" rev-parse --short "$commit" 2>/dev/null)
5362

5463
# 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
6372
fi
6473
if [ -z "$resolved" ]; then
6574
echo "=== $commit: not a commit in this repository"
66-
echo "unresolved" > "$results/$commit.status"
75+
echo "unresolved" > "$results/$key.status"
6776
continue
6877
fi
6978

7079
echo "=== $commit ($resolved)"
71-
tree="$work/$commit"
80+
tree="$work/$key"
7281
rm -rf "$tree"; mkdir -p "$tree"
73-
git -C "$repository" archive "$commit" | tar -x -C "$tree" || { echo "archive failed" > "$results/$commit.status"; continue; }
82+
git -C "$repository" archive "$commit" | tar -x -C "$tree" || { echo "archive failed" > "$results/$key.status"; continue; }
7483

7584
# The benchmark from HEAD, so every row is asked the same question.
7685
rm -rf "$tree/$benchmark"
@@ -83,24 +92,24 @@ for commit in $commits; do
8392
# the row with it: MatchedRules and Patterns were internal until v2.3.0, and
8493
# Transformation.Rationalization did not exist until after v2.1.0. Passed for every row
8594
# including master, so what is compiled does not vary between columns.
86-
if ! (cd "$tree/$benchmark" && dotnet build -c Release -p:InterVersionOnly=true > "$results/$commit.build.log" 2>&1); then
87-
echo " did not build — see $results/$commit.build.log"
88-
echo "did not build" > "$results/$commit.status"
95+
if ! (cd "$tree/$benchmark" && dotnet build -c Release -p:InterVersionOnly=true > "$results/$key.build.log" 2>&1); then
96+
echo " did not build — see $results/$key.build.log"
97+
echo "did not build" > "$results/$key.status"
8998
continue
9099
fi
91-
if ! (cd "$tree/$benchmark" && dotnet run -c Release --no-build CommonFunctionsInterVersion > "$results/$commit.run.log" 2>&1); then
92-
echo " did not run — see $results/$commit.run.log"
93-
echo "did not run" > "$results/$commit.status"
100+
if ! (cd "$tree/$benchmark" && dotnet run -c Release --no-build CommonFunctionsInterVersion > "$results/$key.run.log" 2>&1); then
101+
echo " did not run — see $results/$key.run.log"
102+
echo "did not run" > "$results/$key.status"
94103
continue
95104
fi
96105

97106
measured="$tree/$benchmark/benchmark_results.csv/measured-CommonFunctionsInterVersion.json"
98107
if [ -f "$measured" ]; then
99-
cp "$measured" "$results/$commit.json"
100-
echo "measured $resolved" > "$results/$commit.status"
108+
cp "$measured" "$results/$key.json"
109+
echo "measured $resolved" > "$results/$key.status"
101110
echo " measured"
102111
else
103-
echo "ran but wrote nothing" > "$results/$commit.status"
112+
echo "ran but wrote nothing" > "$results/$key.status"
104113
echo " ran but wrote no results file"
105114
fi
106115
done

‎Sources/Utils/combine_key_commits.py‎

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ def read_list(path):
2626
if line.strip() and not line.strip().startswith("#")]
2727

2828

29-
def read_results(directory, commit):
30-
status_path = os.path.join(directory, commit + ".status")
29+
def read_results(directory, key):
30+
status_path = os.path.join(directory, key + ".status")
3131
status = "not attempted"
3232
if os.path.exists(status_path):
3333
with open(status_path) as handle:
3434
status = handle.read().strip()
35-
measured_path = os.path.join(directory, commit + ".json")
35+
measured_path = os.path.join(directory, key + ".json")
3636
measured = None
3737
if os.path.exists(measured_path):
3838
with open(measured_path) as handle:
@@ -70,14 +70,26 @@ def column(measured, benchmark, field):
7070
return None if value is None else float(value)
7171

7272

73-
def table(handle, commits, results, benchmarks, field, unit, heading, note):
73+
def labels_of(commits):
74+
"""A column heading per entry. A commit named more than once is a column per occurrence,
75+
marked `(2)`, `(3)`, so a control measured twice in one run reads as two measurements."""
76+
total = {commit: commits.count(commit) for commit in commits}
77+
seen = {}
78+
labels = []
79+
for commit in commits:
80+
seen[commit] = seen.get(commit, 0) + 1
81+
labels.append(commit if total[commit] == 1 else "%s (%d)" % (commit, seen[commit]))
82+
return labels
83+
84+
85+
def table(handle, labels, results, benchmarks, field, unit, heading, note):
7486
handle.write("\n### %s\n\n%s\n\n" % (heading, note))
75-
handle.write("| benchmark | " + " | ".join(commits) + " |\n")
76-
handle.write("|---" * (len(commits) + 1) + "|\n")
87+
handle.write("| benchmark | " + " | ".join(labels) + " |\n")
88+
handle.write("|---" * (len(labels) + 1) + "|\n")
7789
for benchmark in benchmarks:
7890
cells = []
79-
for commit in commits:
80-
value = column(results[commit][1], benchmark, field)
91+
for position in range(len(labels)):
92+
value = column(results[position][1], benchmark, field)
8193
cells.append("—" if value is None else "{:,.0f}".format(value))
8294
handle.write("| `%s` | %s |\n" % (benchmark, " | ".join(cells)))
8395
handle.write("\nIn %s. A dash is a commit this benchmark has no figure for.\n" % unit)
@@ -91,11 +103,13 @@ def main():
91103
list_path, results_directory, output = sys.argv[1:4]
92104

93105
commits = read_list(list_path)
94-
results = {commit: read_results(results_directory, commit) for commit in commits}
106+
labels = labels_of(commits)
107+
# Keyed by position, as benchmark_key_commits.sh writes them: entry 1 is `1.json`.
108+
results = [read_results(results_directory, str(position + 1))
109+
for position in range(len(commits))]
95110

96111
benchmarks = []
97-
for commit in commits:
98-
measured = results[commit][1]
112+
for measured in (result[1] for result in results):
99113
if measured:
100114
for name in measured:
101115
if name not in benchmarks:
@@ -109,19 +123,19 @@ def main():
109123
"differs, which is what makes the columns comparable.\n\n")
110124

111125
handle.write("| commit | outcome |\n|---|---|\n")
112-
for commit in commits:
113-
handle.write("| `%s` | %s |\n" % (commit, results[commit][0]))
126+
for label, result in zip(labels, results):
127+
handle.write("| `%s` | %s |\n" % (label, result[0]))
114128

115129
if not benchmarks:
116130
handle.write("\nNothing was measured, so there is no table to draw.\n")
117131
return 0
118132

119-
table(handle, commits, results, benchmarks, "allocatedBytes", "bytes allocated",
133+
table(handle, labels, results, benchmarks, "allocatedBytes", "bytes allocated",
120134
"Allocation",
121135
"**This is the one to read.** Allocation is deterministic — the same commit "
122136
"measured twice gives the same bytes — so a difference between two columns is a "
123137
"difference in the code rather than in the machine.")
124-
table(handle, commits, results, benchmarks, "meanNanoseconds", "nanoseconds",
138+
table(handle, labels, results, benchmarks, "meanNanoseconds", "nanoseconds",
125139
"Time",
126140
"Reported rather than relied on. On a shared runner this project has seen the "
127141
"same unchanged commit come back 30-57% apart, while its allocation over the same "

0 commit comments

Comments
 (0)