Repository navigation
Expand file tree
/
Copy pathcompare.py
More file actions
executable file
·169 lines (134 loc) · 5.09 KB
/
Copy pathcompare.py
File metadata and controls
executable file
·169 lines (134 loc) · 5.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/env python3
import json
import argparse
import statistics
import math
from scipy import stats
from tabulate import tabulate
def confidence_interval(data, confidence=0.95):
n = len(data)
mean = statistics.mean(data)
stderr = statistics.stdev(data) / math.sqrt(n) if n > 1 else 0
interval = stderr * stats.t.ppf((1 + confidence) / 2., n-1) if n > 1 else 0
return mean - interval, mean + interval
def format_mean_confidence_interval(data):
lo, hi = confidence_interval(data)
mean = statistics.mean(data)
if lo == hi:
return f"{mean:.2f}"
return f"{mean:.2f} ± {hi - mean:.2f}"
def extract_tests(data):
rows = []
for benchmark, tests in data.items():
for test_key, metrics in tests.items():
if test_key == "_total":
continue
if "/" in test_key:
suite_name, test_name = test_key.split("/", 1)
else:
suite_name = ""
test_name = test_key
time_data = metrics.get("time")
if not isinstance(time_data, dict):
continue
values = time_data.get("runs", [])
if not values:
continue
rows.append({
"benchmark": benchmark,
"suite": suite_name,
"test": test_name,
"values": values,
})
return rows
def extract_scores(data):
scores = {}
for benchmark, tests in data.items():
total = tests.get("_total", {})
if total:
scores[benchmark] = {
"reported_score": total.get("reported_score", {}).get("runs", []),
"totalTime": total.get("time", {}).get("runs", []),
}
return scores
def main():
parser = argparse.ArgumentParser(description="Compare JavaScript benchmark results (old vs new).")
parser.add_argument("-o", "--old", required=True, help="Old JSON results file.")
parser.add_argument("-n", "--new", required=True, help="New JSON results file.")
args = parser.parse_args()
with open(args.old, "r") as f:
old_data = json.load(f)
with open(args.new, "r") as f:
new_data = json.load(f)
old_tests = { (r["benchmark"], r["suite"], r["test"]): r["values"] for r in extract_tests(old_data) }
new_tests = { (r["benchmark"], r["suite"], r["test"]): r["values"] for r in extract_tests(new_data) }
table = []
all_keys = set(old_tests.keys()) | set(new_tests.keys())
for key in sorted(all_keys):
benchmark, suite, test = key
old_vals = old_tests.get(key, [])
new_vals = new_tests.get(key, [])
if not old_vals or not new_vals:
old_str = format_mean_confidence_interval(old_vals) if old_vals else "—"
new_str = format_mean_confidence_interval(new_vals) if new_vals else "—"
speedup = ""
else:
old_mean = statistics.mean(old_vals)
new_mean = statistics.mean(new_vals)
speedup = f"{old_mean / new_mean:.3f}"
old_str = format_mean_confidence_interval(old_vals)
new_str = format_mean_confidence_interval(new_vals)
table.append([
benchmark,
suite,
test,
speedup,
old_str,
new_str
])
print(tabulate(table, headers=["Benchmark", "Suite", "Test", "Speedup", "Old (Mean ± Range)", "New (Mean ± Range)"]))
old_scores = extract_scores(old_data)
new_scores = extract_scores(new_data)
score_table = []
all_benchmarks = set(old_scores.keys()) | set(new_scores.keys())
for bench in sorted(all_benchmarks):
old = old_scores.get(bench, {})
new = new_scores.get(bench, {})
old_score = old.get("reported_score", [])
new_score = new.get("reported_score", [])
old_time = old.get("totalTime", [])
new_time = new.get("totalTime", [])
score_improvement = ""
speedup = ""
if old_score and new_score:
old_score_mean = statistics.mean(old_score)
new_score_mean = statistics.mean(new_score)
score_improvement = f"{new_score_mean / old_score_mean:.3f}" if old_score_mean else "—"
if old_time and new_time:
old_time_mean = statistics.mean(old_time)
new_time_mean = statistics.mean(new_time)
speedup = f"{old_time_mean / new_time_mean:.3f}" if new_time_mean else "—"
score_table.append([
bench,
format_mean_confidence_interval(old_score),
format_mean_confidence_interval(new_score),
score_improvement or "—",
format_mean_confidence_interval(old_time),
format_mean_confidence_interval(new_time),
speedup or "—",
])
print()
print(tabulate(
score_table,
headers=[
"Benchmark",
"Old Score",
"New Score",
"Score Improvement",
"Old Total Time (s)",
"New Total Time (s)",
"Speedup"
],
))
if __name__ == "__main__":
main()