react-nitro-hermes 0.0.1-alpha.8 → 0.0.1-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/hermes/CMakeLists.txt +874 -0
- package/hermes/android/HostObjectJniTest.cpp +178 -0
- package/hermes/android/build-logic/build.gradle.kts +31 -0
- package/hermes/android/build-logic/settings.gradle.kts +17 -0
- package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/helpers/internal/SerializeHermesCompilerPackageJson.kt +33 -0
- package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/plugins/internal/TestUtilsPlugin.kt +80 -0
- package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/tasks/internal/CustomExecTask.kt +46 -0
- package/hermes/android/build-logic/src/main/kotlin/publish.gradle.kts +82 -0
- package/hermes/android/build.gradle.kts +332 -0
- package/hermes/android/cppruntime/build.gradle +72 -0
- package/hermes/android/cppruntime/src/main/AndroidManifest.xml +2 -0
- package/hermes/android/cppruntime/src/main/cpp/CMakeLists.txt +8 -0
- package/hermes/android/cppruntime/src/main/cpp/stub.cpp +12 -0
- package/hermes/android/cross-compile/swift-libicu.patch +13 -0
- package/hermes/android/cross-compile/toolchain-android-arm-api13-gnustl.cmake +13 -0
- package/hermes/android/cross-compile/toolchain-android-arm-api15-gnustl.cmake +14 -0
- package/hermes/android/gradle/libs.versions.toml +30 -0
- package/hermes/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/hermes/android/gradle/wrapper/gradle-wrapper.properties +7 -0
- package/hermes/android/gradle.properties +3 -0
- package/hermes/android/gradlew +248 -0
- package/hermes/android/gradlew.bat +93 -0
- package/hermes/android/intltest/build.gradle +147 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/CMakeLists.txt +45 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.cpp +68 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.h +44 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.java +45 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogueTestData.java +32 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesInstrumentationTest.java +150 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesIntlAndroidTest.java +147 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesIntlTest262.java +470 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesRuntimeFactory.cpp +73 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.cpp +90 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.h +62 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.java +155 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/MappedFileBuffer.cpp +48 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/MappedFileBuffer.h +36 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/OnLoad.cpp +13 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/OnLoadEpilogue.cpp +13 -0
- package/hermes/android/intltest/src/main/AndroidManifest.xml +2 -0
- package/hermes/android/ios-artifacts/build.gradle.kts +65 -0
- package/hermes/android/settings.gradle.kts +27 -0
- package/hermes/cmake/modules/Hermes.cmake +481 -0
- package/hermes/cmake/modules/Lit.cmake +96 -0
- package/hermes/doc/Branches.md +38 -0
- package/hermes/doc/BuildingAndRunning.md +121 -0
- package/hermes/doc/CodingStandards.md +112 -0
- package/hermes/doc/CrossCompilation.md +79 -0
- package/hermes/doc/Design.md +217 -0
- package/hermes/doc/Emscripten.md +156 -0
- package/hermes/doc/Features.md +143 -0
- package/hermes/doc/GCSafeCoding.md +563 -0
- package/hermes/doc/GenGC.md +300 -0
- package/hermes/doc/Hades.md +344 -0
- package/hermes/doc/HighLevelOptimizations.md +37 -0
- package/hermes/doc/IR.md +1306 -0
- package/hermes/doc/IntlAPIs.md +196 -0
- package/hermes/doc/JIT.md +999 -0
- package/hermes/doc/LazyEvalCompilation.md +84 -0
- package/hermes/doc/MemoryProfilers.md +316 -0
- package/hermes/doc/Modules.md +144 -0
- package/hermes/doc/Optimizer.md +83 -0
- package/hermes/doc/PerfProfiling.md +29 -0
- package/hermes/doc/ProhibitInvoke.md +329 -0
- package/hermes/doc/ReactNative.md +40 -0
- package/hermes/doc/ReactNativeIntegration.md +94 -0
- package/hermes/doc/RegExp.md +24 -0
- package/hermes/doc/SpecIncompat.md +85 -0
- package/hermes/doc/Strings.md +140 -0
- package/hermes/doc/TypedLanguage.md +432 -0
- package/hermes/doc/VM.md +174 -0
- package/hermes/doc/blog/2024-11-09-octane-benchmark-jit-progress.md +17 -0
- package/hermes/doc/blog/2024-12-19-static-hermes-update-dec-2024.md +47 -0
- package/hermes/doc/blog/2024-12-23-compiling-javascript-to-wasm.md +267 -0
- package/hermes/doc/blog/2025-06-09-jsi-runtime-data-apis.md +23 -0
- package/hermes/doc/blog/2025-07-15-static-h-performance-june-2025.md +18 -0
- package/hermes/doc/blog/2025-11-02-hermes-compilation-runtime-modes.md +23 -0
- package/hermes/doc/blog/2025-11-06-hermes-memory-modes.md +35 -0
- package/hermes/doc/blog/2025-11-24-json-parsing-performance.md +17 -0
- package/hermes/doc/blog/2025-12-02-iserialization.md +11 -0
- package/hermes/doc/blog/2025-12-12-new-way-to-contribute.md +68 -0
- package/hermes/doc/blog/2026-06-05-new-hermes-stable-release.md +51 -0
- package/hermes/doc/blog/README.md +25 -0
- package/hermes/doc/blog/images/2024-11-09-octane-pi3.jpeg +0 -0
- package/hermes/doc/blog/images/2024-11-09-octane-pi5.jpeg +0 -0
- package/hermes/doc/blog/images/2025-07-15-perf-hv32-interpreter.jpeg +0 -0
- package/hermes/doc/blog/images/2025-07-15-perf-hv32-jit.jpeg +0 -0
- package/hermes/doc/icu_license.txt +420 -0
- package/hermes/doc/img/heap_snapshot_retainers.png +0 -0
- package/hermes/doc/img/logo.svg +1 -0
- package/hermes/doc/img/object_captured_by_environment.png +0 -0
- package/hermes/doc/img/root_categories.png +0 -0
- package/hermes/doc/plans/ir-type/flow-type-system.md +324 -0
- package/hermes/doc/plans/ir-type/ir-type-system-v2-design.md +652 -0
- package/hermes/doc/plans/ir-type/ir-type-system.md +220 -0
- package/hermes/doc/plans/ir-type/ir-type-v2-implementation.md +1187 -0
- package/hermes/doc/plans/ir-type/memory.md +48 -0
- package/hermes/doc/plans/ir-type/phase1-steps.md +512 -0
- package/hermes/doc/plans/ir-type/progress.md +239 -0
- package/hermes/doc/plans/ir-type/typeinference-primitive-fastpath-design.md +203 -0
- package/hermes/doc/plans/ir-type/typeinference-primitive-fastpath-results.md +71 -0
- package/hermes/doc/superpowers/plans/2026-07-28-worker-arraybuffer-input.md +597 -0
- package/hermes/doc/superpowers/plans/2026-08-18-jitemitter-split.md +1149 -0
- package/hermes/doc/superpowers/plans/2026-08-20-jit-type-asserts.md +969 -0
- package/hermes/doc/superpowers/plans/2026-08-23-jit-shared-compiler-driver.md +478 -0
- package/hermes/doc/superpowers/plans/2026-08-23-x86-64-jit-skeleton.md +797 -0
- package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-arith.md +444 -0
- package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-calls.md +261 -0
- package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-props.md +240 -0
- package/hermes/doc/superpowers/plans/2026-10-26-regexp-bytecode-sharing.md +2197 -0
- package/hermes/doc/superpowers/plans/2026-10-28-regexp-start-filter-and-exec-fast-paths.md +3981 -0
- package/hermes/doc/superpowers/specs/2026-07-28-worker-arraybuffer-input-design.md +206 -0
- package/hermes/doc/superpowers/specs/2026-08-18-jitemitter-split-design.md +530 -0
- package/hermes/doc/superpowers/specs/2026-08-20-jit-type-asserts-design.md +360 -0
- package/hermes/doc/superpowers/specs/2026-08-23-x86-64-jit-design.md +246 -0
- package/hermes/doc/superpowers/specs/2026-08-26-icu-free-normalize-design.md +355 -0
- package/hermes/doc/superpowers/specs/2026-08-27-icu-free-convert-to-case-design.md +305 -0
- package/hermes/doc/superpowers/specs/2026-08-27-icu-free-locale-compare-design.md +429 -0
- package/hermes/doc/superpowers/specs/2026-08-29-icu-free-date-format-design.md +297 -0
- package/hermes/doc/superpowers/specs/2026-10-26-regexp-bytecode-sharing-design.md +605 -0
- package/hermes/doc/superpowers/specs/2026-10-28-regexp-start-filter-and-exec-fast-paths-design.md +551 -0
- package/hermes/doc/typescript-stripping.md +90 -0
- package/hermes/external/CMakeLists.txt +20 -0
- package/hermes/utils/IntlGen/IntlGen.java +531 -0
- package/hermes/utils/bench_with_stats.py +827 -0
- package/hermes/utils/build-apple-framework.sh +323 -0
- package/hermes/utils/chrome_snapshot_parser.py +210 -0
- package/hermes/utils/cmake-dev-build.sh +18 -0
- package/hermes/utils/commons.sh +55 -0
- package/hermes/utils/dump-cpp-funcs.sh +3 -0
- package/hermes/utils/es5objects.js +198 -0
- package/hermes/utils/format.sh +145 -0
- package/hermes/utils/gen-promise-internal-bc.sh +66 -0
- package/hermes/utils/genUnicodeTable.py +2503 -0
- package/hermes/utils/hermes-lit/CMakeLists.txt +22 -0
- package/hermes/utils/hermes-lit/hermes-lit.in +15 -0
- package/hermes/utils/jit/README.md +134 -0
- package/hermes/utils/jit/jit-diff.sh +160 -0
- package/hermes/utils/jit/jit-dump.sh +193 -0
- package/hermes/utils/lit-expect-gen/generate.py +217 -0
- package/hermes/utils/promise/index.js +15 -0
- package/hermes/utils/promise/package.json +13 -0
- package/hermes/utils/promise/rollup.config.js +19 -0
- package/hermes/utils/promise/yarn.lock +247 -0
- package/hermes/utils/scripts/hermes/consts.js +26 -0
- package/hermes/utils/scripts/hermes/create-tarball.js +75 -0
- package/hermes/utils/scripts/hermes/get-hermes-version.js +57 -0
- package/hermes/utils/scripts/hermes/hermes-utils.js +122 -0
- package/hermes/utils/scripts/hermes/package.json +6 -0
- package/hermes/utils/scripts/hermes/prepare-artifacts.js +113 -0
- package/hermes/utils/scripts/hermes/publish-artifacts.js +109 -0
- package/hermes/utils/scripts/hermes/publish-npm.js +96 -0
- package/hermes/utils/scripts/hermes/scm-utils.js +41 -0
- package/hermes/utils/scripts/hermes/set-artifacts-version.js +64 -0
- package/hermes/utils/scripts/hermes/version-utils.js +98 -0
- package/hermes/utils/scripts/hermes/yarn.lock +240 -0
- package/hermes/utils/summarize_sizes.py +184 -0
- package/hermes/utils/symbolicate-nativecall-stats.py +112 -0
- package/hermes/utils/test_runner.py +13 -0
- package/hermes/utils/testsuite/README.facebook +3 -0
- package/hermes/utils/testsuite/README.md +69 -0
- package/hermes/utils/testsuite/cli.py +547 -0
- package/hermes/utils/testsuite/es_ast.py +337 -0
- package/hermes/utils/testsuite/external/LICENSE +28 -0
- package/hermes/utils/testsuite/external/README.facebook +8 -0
- package/hermes/utils/testsuite/external/__init__.py +0 -0
- package/hermes/utils/testsuite/external/_monkeyYaml.py +164 -0
- package/hermes/utils/testsuite/external/parse_test262.py +141 -0
- package/hermes/utils/testsuite/hermes.py +522 -0
- package/hermes/utils/testsuite/preprocess.py +365 -0
- package/hermes/utils/testsuite/progress.py +377 -0
- package/hermes/utils/testsuite/skiplist.json +4356 -0
- package/hermes/utils/testsuite/skiplist.py +270 -0
- package/hermes/utils/testsuite/test_run_defs.py +435 -0
- package/hermes/utils/testsuite/typing_defs.py +52 -0
- package/hermes/utils/testsuite/utils.py +214 -0
- package/hermes/utils/tidy.sh +22 -0
- package/hermes/utils/update-fbcode-hermes.sh +53 -0
- package/hermes/utils/updateErrorTest.py +193 -0
- package/hermes/utils/wasm-compile.sh +65 -0
- package/package.json +1 -1
|
@@ -0,0 +1,827 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
#
|
|
4
|
+
# This source code is licensed under the MIT license found in the
|
|
5
|
+
# LICENSE file in the root directory of this source tree.
|
|
6
|
+
|
|
7
|
+
import argparse
|
|
8
|
+
import csv
|
|
9
|
+
import math # Needed for infinity when sorting N/A values
|
|
10
|
+
import os
|
|
11
|
+
import re
|
|
12
|
+
import shlex
|
|
13
|
+
import statistics
|
|
14
|
+
import subprocess
|
|
15
|
+
import sys
|
|
16
|
+
from collections import defaultdict
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def find_first_score(output_text):
|
|
20
|
+
"""Finds the first line matching 'Name: Score' and returns the score as float."""
|
|
21
|
+
pattern = re.compile(r":?\s*(\d+(?:\.\d+)?)\s*$")
|
|
22
|
+
for line in output_text.strip().split("\n"):
|
|
23
|
+
match = pattern.search(line.strip())
|
|
24
|
+
if match:
|
|
25
|
+
try:
|
|
26
|
+
return float(match.group(1))
|
|
27
|
+
except ValueError:
|
|
28
|
+
continue
|
|
29
|
+
return None
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def run_command(command_parts, filename):
|
|
33
|
+
"""Runs the command and returns the completed process object."""
|
|
34
|
+
cmd = command_parts + [filename]
|
|
35
|
+
env = os.environ.copy()
|
|
36
|
+
env["PATH"] = f".:{env.get('PATH', '')}"
|
|
37
|
+
result = subprocess.run(
|
|
38
|
+
cmd,
|
|
39
|
+
capture_output=True,
|
|
40
|
+
text=True,
|
|
41
|
+
check=False, # Don't raise error on non-zero exit
|
|
42
|
+
env=env,
|
|
43
|
+
)
|
|
44
|
+
return result
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def format_change_line(avg_pct, stdev_pct, num_valid_runs):
|
|
48
|
+
"""Formats the 'Change: ...' line based on calculated values."""
|
|
49
|
+
if avg_pct is None:
|
|
50
|
+
# Handle cases where no valid data could be gathered
|
|
51
|
+
if num_valid_runs == 0:
|
|
52
|
+
return "Change: N/A (No valid score pairs found)"
|
|
53
|
+
else: # Should mean avg_old was 0
|
|
54
|
+
return (
|
|
55
|
+
f"Change: N/A (Average OLD score is 0 from {num_valid_runs} valid runs)"
|
|
56
|
+
)
|
|
57
|
+
elif stdev_pct is not None:
|
|
58
|
+
return f"Change: {avg_pct:+.1f}% +/- {stdev_pct:.1f}% (from {num_valid_runs} valid runs)"
|
|
59
|
+
else: # Only average is available (1 valid run)
|
|
60
|
+
return f"Change: {avg_pct:+.1f}% (from {num_valid_runs} valid run, +/- N/A)"
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def manual_ttest_confidence_interval(data1, data2, confidence=0.95):
|
|
64
|
+
"""Calculate confidence interval manually without scipy dependency."""
|
|
65
|
+
if len(data1) < 2 or len(data2) < 2:
|
|
66
|
+
return (None, None)
|
|
67
|
+
|
|
68
|
+
# t-distribution critical values for common confidence levels and degrees of freedom
|
|
69
|
+
t_values = {
|
|
70
|
+
0.90: {
|
|
71
|
+
1: 6.314,
|
|
72
|
+
2: 2.920,
|
|
73
|
+
3: 2.353,
|
|
74
|
+
4: 2.132,
|
|
75
|
+
5: 2.015,
|
|
76
|
+
6: 1.943,
|
|
77
|
+
7: 1.895,
|
|
78
|
+
8: 1.860,
|
|
79
|
+
9: 1.833,
|
|
80
|
+
10: 1.812,
|
|
81
|
+
15: 1.753,
|
|
82
|
+
20: 1.725,
|
|
83
|
+
25: 1.708,
|
|
84
|
+
30: 1.697,
|
|
85
|
+
40: 1.684,
|
|
86
|
+
60: 1.671,
|
|
87
|
+
120: 1.658,
|
|
88
|
+
float("inf"): 1.645,
|
|
89
|
+
},
|
|
90
|
+
0.95: {
|
|
91
|
+
1: 12.706,
|
|
92
|
+
2: 4.303,
|
|
93
|
+
3: 3.182,
|
|
94
|
+
4: 2.776,
|
|
95
|
+
5: 2.571,
|
|
96
|
+
6: 2.447,
|
|
97
|
+
7: 2.365,
|
|
98
|
+
8: 2.306,
|
|
99
|
+
9: 2.262,
|
|
100
|
+
10: 2.228,
|
|
101
|
+
15: 2.131,
|
|
102
|
+
20: 2.086,
|
|
103
|
+
25: 2.060,
|
|
104
|
+
30: 2.042,
|
|
105
|
+
40: 2.021,
|
|
106
|
+
60: 2.000,
|
|
107
|
+
120: 1.980,
|
|
108
|
+
float("inf"): 1.960,
|
|
109
|
+
},
|
|
110
|
+
0.99: {
|
|
111
|
+
1: 63.657,
|
|
112
|
+
2: 9.925,
|
|
113
|
+
3: 5.841,
|
|
114
|
+
4: 4.604,
|
|
115
|
+
5: 4.032,
|
|
116
|
+
6: 3.707,
|
|
117
|
+
7: 3.499,
|
|
118
|
+
8: 3.355,
|
|
119
|
+
9: 3.250,
|
|
120
|
+
10: 3.169,
|
|
121
|
+
15: 2.947,
|
|
122
|
+
20: 2.845,
|
|
123
|
+
25: 2.787,
|
|
124
|
+
30: 2.750,
|
|
125
|
+
40: 2.704,
|
|
126
|
+
60: 2.660,
|
|
127
|
+
120: 2.617,
|
|
128
|
+
float("inf"): 2.576,
|
|
129
|
+
},
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
n1, n2 = len(data1), len(data2)
|
|
133
|
+
df = n1 + n2 - 2 # degrees of freedom
|
|
134
|
+
|
|
135
|
+
# Get t-critical value
|
|
136
|
+
if confidence not in t_values:
|
|
137
|
+
return (None, None)
|
|
138
|
+
|
|
139
|
+
t_table = t_values[confidence]
|
|
140
|
+
t_crit = None
|
|
141
|
+
|
|
142
|
+
# Find appropriate t-critical value for degrees of freedom
|
|
143
|
+
for deg_freedom in sorted(t_table.keys()):
|
|
144
|
+
if df <= deg_freedom:
|
|
145
|
+
t_crit = t_table[deg_freedom]
|
|
146
|
+
break
|
|
147
|
+
|
|
148
|
+
if t_crit is None:
|
|
149
|
+
# Use infinity value for very large df
|
|
150
|
+
t_crit = t_table[float("inf")]
|
|
151
|
+
|
|
152
|
+
# Calculate means and variances
|
|
153
|
+
mean1, mean2 = statistics.mean(data1), statistics.mean(data2)
|
|
154
|
+
var1 = statistics.variance(data1) if len(data1) > 1 else 0
|
|
155
|
+
var2 = statistics.variance(data2) if len(data2) > 1 else 0
|
|
156
|
+
|
|
157
|
+
# Pooled variance and standard error
|
|
158
|
+
if df == 0:
|
|
159
|
+
return (None, None)
|
|
160
|
+
pooled_var = ((n1 - 1) * var1 + (n2 - 1) * var2) / df
|
|
161
|
+
se = math.sqrt(pooled_var * (1 / n1 + 1 / n2))
|
|
162
|
+
|
|
163
|
+
if se == 0:
|
|
164
|
+
return (None, None)
|
|
165
|
+
|
|
166
|
+
# Difference of means and margin of error
|
|
167
|
+
# Note: data1=new_scores, data2=old_scores, so mean1-mean2 = new-old
|
|
168
|
+
diff = mean1 - mean2
|
|
169
|
+
margin = t_crit * se
|
|
170
|
+
|
|
171
|
+
return (diff - margin, diff + margin)
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def calculate_geometric_mean(percentages):
|
|
175
|
+
"""Calculate geometric mean of percentage improvements.
|
|
176
|
+
|
|
177
|
+
Args:
|
|
178
|
+
percentages: List of percentage changes (e.g., [10.5, -5.2, 15.3])
|
|
179
|
+
|
|
180
|
+
Returns:
|
|
181
|
+
Geometric mean as a percentage, or None if calculation not possible
|
|
182
|
+
"""
|
|
183
|
+
if not percentages:
|
|
184
|
+
return None
|
|
185
|
+
|
|
186
|
+
# Convert percentages to multiplicative factors (e.g., +10% -> 1.10)
|
|
187
|
+
factors = [1 + (p / 100) for p in percentages]
|
|
188
|
+
|
|
189
|
+
# Check for non-positive factors (would make geometric mean undefined)
|
|
190
|
+
if any(f <= 0 for f in factors):
|
|
191
|
+
return None
|
|
192
|
+
|
|
193
|
+
# Calculate geometric mean of factors
|
|
194
|
+
product = 1.0
|
|
195
|
+
for f in factors:
|
|
196
|
+
product *= f
|
|
197
|
+
|
|
198
|
+
geo_mean_factor = product ** (1.0 / len(factors))
|
|
199
|
+
|
|
200
|
+
# Convert back to percentage change
|
|
201
|
+
return (geo_mean_factor - 1) * 100
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def calculate_geometric_mean_ratios(ratios):
|
|
205
|
+
"""Calculate geometric mean of ratios.
|
|
206
|
+
|
|
207
|
+
Args:
|
|
208
|
+
ratios: List of ratios (e.g., [1.18, 0.89, 1.05])
|
|
209
|
+
|
|
210
|
+
Returns:
|
|
211
|
+
Geometric mean of ratios, or None if calculation not possible
|
|
212
|
+
"""
|
|
213
|
+
if not ratios or any(r <= 0 for r in ratios):
|
|
214
|
+
return None
|
|
215
|
+
product = 1.0
|
|
216
|
+
for r in ratios:
|
|
217
|
+
product *= r
|
|
218
|
+
return product ** (1.0 / len(ratios))
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def print_per_benchmark_table(benchmark_result, display_format, confidence):
|
|
222
|
+
"""Prints detailed table for a single benchmark with all engines."""
|
|
223
|
+
engines = benchmark_result["engines"]
|
|
224
|
+
if not engines:
|
|
225
|
+
return
|
|
226
|
+
|
|
227
|
+
# Determine column widths
|
|
228
|
+
max_engine_len = (
|
|
229
|
+
max(
|
|
230
|
+
len(f"engine{e['index'] + 1} {'(base)' if e['index'] == 0 else ''}")
|
|
231
|
+
for e in engines
|
|
232
|
+
)
|
|
233
|
+
+ 2
|
|
234
|
+
)
|
|
235
|
+
score_width = 11
|
|
236
|
+
vs_base_width = 11
|
|
237
|
+
conf_width = 17
|
|
238
|
+
stdev_width = 11
|
|
239
|
+
runs_width = 11
|
|
240
|
+
|
|
241
|
+
# Header
|
|
242
|
+
print(f"--- Results for {benchmark_result['name']} (baseline: engine1) ---")
|
|
243
|
+
header = f"+-{'-' * max_engine_len}-+-{'-' * score_width}-+-{'-' * vs_base_width}-+-{'-' * conf_width}-+-{'-' * stdev_width}-+-{'-' * runs_width}-+"
|
|
244
|
+
print(header)
|
|
245
|
+
print(
|
|
246
|
+
f"| {'Engine'.ljust(max_engine_len)} | {'Avg Score'.rjust(score_width)} | {'vs Base'.rjust(vs_base_width)} | "
|
|
247
|
+
f"{(str(round(confidence * 100)) + '% CI').rjust(conf_width)} | {'Stdev'.rjust(stdev_width)} | {'Valid Runs'.rjust(runs_width)} |"
|
|
248
|
+
)
|
|
249
|
+
print(header)
|
|
250
|
+
|
|
251
|
+
# Data rows
|
|
252
|
+
for engine in engines:
|
|
253
|
+
# Engine name
|
|
254
|
+
engine_name = f"engine{engine['index'] + 1}"
|
|
255
|
+
if engine["index"] == 0:
|
|
256
|
+
engine_name += " (base)"
|
|
257
|
+
engine_name = engine_name.ljust(max_engine_len)
|
|
258
|
+
|
|
259
|
+
# Average score
|
|
260
|
+
avg_score_str = f"{engine['avg_score']:.1f}".rjust(score_width)
|
|
261
|
+
|
|
262
|
+
# vs Base
|
|
263
|
+
if engine["index"] == 0:
|
|
264
|
+
vs_base_str = "-".rjust(vs_base_width)
|
|
265
|
+
else:
|
|
266
|
+
if display_format == "percentage" and engine["vs_baseline_pct"] is not None:
|
|
267
|
+
vs_base_str = f"{engine['vs_baseline_pct']:+.1f}%".rjust(vs_base_width)
|
|
268
|
+
elif engine["vs_baseline_ratio"] is not None:
|
|
269
|
+
vs_base_str = f"{engine['vs_baseline_ratio']:.2f}x".rjust(vs_base_width)
|
|
270
|
+
else:
|
|
271
|
+
vs_base_str = "N/A".rjust(vs_base_width)
|
|
272
|
+
|
|
273
|
+
# Confidence interval
|
|
274
|
+
conf_int = engine.get("confidence_interval", (None, None))
|
|
275
|
+
if conf_int[0] is not None:
|
|
276
|
+
conf_str = f"{conf_int[0]:.1f} - {conf_int[1]:.1f}".rjust(conf_width)
|
|
277
|
+
else:
|
|
278
|
+
conf_str = "N/A".rjust(conf_width)
|
|
279
|
+
|
|
280
|
+
# Stdev
|
|
281
|
+
if engine.get("stdev") is not None:
|
|
282
|
+
stdev_str = f"+/- {engine['stdev']:.1f}".rjust(stdev_width)
|
|
283
|
+
else:
|
|
284
|
+
stdev_str = "N/A".rjust(stdev_width)
|
|
285
|
+
|
|
286
|
+
# Valid runs
|
|
287
|
+
runs_str = f"({engine['valid_runs']} runs)".rjust(runs_width)
|
|
288
|
+
|
|
289
|
+
print(
|
|
290
|
+
f"| {engine_name} | {avg_score_str} | {vs_base_str} | {conf_str} | {stdev_str} | {runs_str} |"
|
|
291
|
+
)
|
|
292
|
+
|
|
293
|
+
print(header)
|
|
294
|
+
print()
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def print_compact_summary_table(
|
|
298
|
+
title, all_results, display_format, num_engines, sort_by_last=False
|
|
299
|
+
):
|
|
300
|
+
"""Prints compact summary table with all benchmarks and engines."""
|
|
301
|
+
if not all_results:
|
|
302
|
+
print(f"\n--- {title} ---")
|
|
303
|
+
print("No data to display.")
|
|
304
|
+
return
|
|
305
|
+
|
|
306
|
+
# Prepare data
|
|
307
|
+
summary_data = []
|
|
308
|
+
for result in all_results:
|
|
309
|
+
row = {"name": result["name"], "comparisons": []}
|
|
310
|
+
for engine_idx in range(1, num_engines):
|
|
311
|
+
# Find this engine in results
|
|
312
|
+
engine_data = None
|
|
313
|
+
for e in result["engines"]:
|
|
314
|
+
if e["index"] == engine_idx:
|
|
315
|
+
engine_data = e
|
|
316
|
+
break
|
|
317
|
+
|
|
318
|
+
if engine_data:
|
|
319
|
+
if display_format == "percentage":
|
|
320
|
+
value = engine_data.get("vs_baseline_pct")
|
|
321
|
+
else:
|
|
322
|
+
value = engine_data.get("vs_baseline_ratio")
|
|
323
|
+
else:
|
|
324
|
+
value = None
|
|
325
|
+
|
|
326
|
+
row["comparisons"].append(value)
|
|
327
|
+
|
|
328
|
+
summary_data.append(row)
|
|
329
|
+
|
|
330
|
+
# Sort if requested
|
|
331
|
+
if sort_by_last and summary_data and summary_data[0]["comparisons"]:
|
|
332
|
+
summary_data = sorted(
|
|
333
|
+
summary_data,
|
|
334
|
+
key=lambda x: x["comparisons"][-1]
|
|
335
|
+
if x["comparisons"][-1] is not None
|
|
336
|
+
else -math.inf,
|
|
337
|
+
reverse=True,
|
|
338
|
+
)
|
|
339
|
+
|
|
340
|
+
# Determine column widths
|
|
341
|
+
max_name_len = max(len(row["name"]) for row in summary_data) if summary_data else 10
|
|
342
|
+
# Also consider "Geometric Mean" and "Benchmark" in the width calculation
|
|
343
|
+
max_name_len = max(max_name_len, len("Geometric Mean"), len("Benchmark"))
|
|
344
|
+
comp_width = 11
|
|
345
|
+
|
|
346
|
+
# Header
|
|
347
|
+
print(f"\n--- {title} ---")
|
|
348
|
+
header = f"+-{'-' * max_name_len}-"
|
|
349
|
+
for _ in range(1, num_engines):
|
|
350
|
+
header += f"+-{'-' * comp_width}-"
|
|
351
|
+
header += "+"
|
|
352
|
+
print(header)
|
|
353
|
+
|
|
354
|
+
# Column headers
|
|
355
|
+
header_row = f"| {'Benchmark'.ljust(max_name_len)} "
|
|
356
|
+
for i in range(1, num_engines):
|
|
357
|
+
header_row += f"| {f'engine{i + 1}/1'.rjust(comp_width)} "
|
|
358
|
+
header_row += "|"
|
|
359
|
+
print(header_row)
|
|
360
|
+
print(header)
|
|
361
|
+
|
|
362
|
+
# Data rows
|
|
363
|
+
for row in summary_data:
|
|
364
|
+
data_row = f"| {row['name'].ljust(max_name_len)} "
|
|
365
|
+
for comp_value in row["comparisons"]:
|
|
366
|
+
if comp_value is not None:
|
|
367
|
+
if display_format == "percentage":
|
|
368
|
+
value_str = f"{comp_value:+.1f}%"
|
|
369
|
+
else:
|
|
370
|
+
value_str = f"{comp_value:.2f}x"
|
|
371
|
+
else:
|
|
372
|
+
value_str = "N/A"
|
|
373
|
+
data_row += f"| {value_str.rjust(comp_width)} "
|
|
374
|
+
data_row += "|"
|
|
375
|
+
print(data_row)
|
|
376
|
+
|
|
377
|
+
# Footer with geometric means
|
|
378
|
+
print(header)
|
|
379
|
+
|
|
380
|
+
# Calculate geometric means for each engine comparison
|
|
381
|
+
geo_means = []
|
|
382
|
+
for engine_idx in range(len(summary_data[0]["comparisons"]) if summary_data else 0):
|
|
383
|
+
values = [
|
|
384
|
+
row["comparisons"][engine_idx]
|
|
385
|
+
for row in summary_data
|
|
386
|
+
if row["comparisons"][engine_idx] is not None
|
|
387
|
+
]
|
|
388
|
+
if values:
|
|
389
|
+
if display_format == "percentage":
|
|
390
|
+
geo_mean = calculate_geometric_mean(values)
|
|
391
|
+
else:
|
|
392
|
+
geo_mean = calculate_geometric_mean_ratios(values)
|
|
393
|
+
geo_means.append(geo_mean)
|
|
394
|
+
else:
|
|
395
|
+
geo_means.append(None)
|
|
396
|
+
|
|
397
|
+
if any(gm is not None for gm in geo_means):
|
|
398
|
+
geo_row = f"| {'Geometric Mean'.ljust(max_name_len)} "
|
|
399
|
+
for gm in geo_means:
|
|
400
|
+
if gm is not None:
|
|
401
|
+
if display_format == "percentage":
|
|
402
|
+
value_str = f"{gm:+.1f}%"
|
|
403
|
+
else:
|
|
404
|
+
value_str = f"{gm:.2f}x"
|
|
405
|
+
else:
|
|
406
|
+
value_str = "N/A"
|
|
407
|
+
geo_row += f"| {value_str.rjust(comp_width)} "
|
|
408
|
+
geo_row += "|"
|
|
409
|
+
print(geo_row)
|
|
410
|
+
print(header)
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
def export_to_csv(filename, all_results, engine_commands):
|
|
414
|
+
"""Export benchmark results to CSV file for easy graphing."""
|
|
415
|
+
with open(filename, "w", newline="") as csvfile:
|
|
416
|
+
# Prepare header
|
|
417
|
+
fieldnames = ["Benchmark"]
|
|
418
|
+
for i, _ in enumerate(engine_commands):
|
|
419
|
+
engine_name = f"Engine{i + 1}"
|
|
420
|
+
fieldnames.append(engine_name)
|
|
421
|
+
|
|
422
|
+
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
|
|
423
|
+
writer.writeheader()
|
|
424
|
+
|
|
425
|
+
# Write data rows
|
|
426
|
+
for result in all_results:
|
|
427
|
+
row = {"Benchmark": result["name"]}
|
|
428
|
+
|
|
429
|
+
# Initialize all engine columns to ensure consistent CSV
|
|
430
|
+
for i in range(len(engine_commands)):
|
|
431
|
+
row[f"Engine{i + 1}"] = ""
|
|
432
|
+
|
|
433
|
+
for engine in result["engines"]:
|
|
434
|
+
engine_idx = engine["index"]
|
|
435
|
+
engine_name = f"Engine{engine_idx + 1}"
|
|
436
|
+
|
|
437
|
+
# Engine 1 is always 1.0, others show their ratio
|
|
438
|
+
if engine_idx == 0:
|
|
439
|
+
row[engine_name] = 1.0
|
|
440
|
+
else:
|
|
441
|
+
ratio = engine.get("vs_baseline_ratio")
|
|
442
|
+
row[engine_name] = ratio if ratio is not None else ""
|
|
443
|
+
|
|
444
|
+
writer.writerow(row)
|
|
445
|
+
|
|
446
|
+
print(f"\nResults exported to: {filename}")
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
def print_summary_table(title, confidence, summary_data):
|
|
450
|
+
"""Prints an ASCII table from the collected summary data."""
|
|
451
|
+
if not summary_data:
|
|
452
|
+
print(f"\n--- {title} ---")
|
|
453
|
+
print("No data to display.")
|
|
454
|
+
return
|
|
455
|
+
|
|
456
|
+
# Determine column widths
|
|
457
|
+
max_name_len = (
|
|
458
|
+
max(len(item["name"]) for item in summary_data) if summary_data else 10
|
|
459
|
+
)
|
|
460
|
+
# Fixed widths for numbers are often cleaner
|
|
461
|
+
avg_width = 10 # e.g., "+100.5%"
|
|
462
|
+
std_width = 10 # e.g., "+/- 10.5%"
|
|
463
|
+
conf_width = 15 # e.g., "+/- 10.5%"
|
|
464
|
+
runs_width = 12 # e.g., "(10 runs)"
|
|
465
|
+
confidence = round(confidence * 100)
|
|
466
|
+
|
|
467
|
+
# Header
|
|
468
|
+
print(f"\n--- {title} ---")
|
|
469
|
+
header = f"+-{'-' * max_name_len}-+-{'-' * avg_width}-+-{'-' * conf_width}-+-{'-' * std_width}-+-{'-' * runs_width}-+"
|
|
470
|
+
print(header)
|
|
471
|
+
print(
|
|
472
|
+
f"| {'Benchmark'.ljust(max_name_len)} | {'Avg Change'.rjust(avg_width)} | {(str(confidence) + '% interval').rjust(conf_width)} | {'Stdev'.rjust(std_width)} | {'Valid Runs'.rjust(runs_width)} |"
|
|
473
|
+
)
|
|
474
|
+
print(header)
|
|
475
|
+
|
|
476
|
+
# Data Rows
|
|
477
|
+
for item in summary_data:
|
|
478
|
+
name = item["name"].ljust(max_name_len)
|
|
479
|
+
avg_str = f"{item['avg_pct']:+.1f}%" if item["avg_pct"] is not None else "N/A"
|
|
480
|
+
avg_str = avg_str.rjust(avg_width)
|
|
481
|
+
(conf_low, conf_high) = item["ttest"]
|
|
482
|
+
conf_str = (
|
|
483
|
+
f"{conf_low:+.1f}% - {conf_high:+.1f}%" if conf_low is not None else "N/A"
|
|
484
|
+
)
|
|
485
|
+
conf_str = conf_str.rjust(conf_width)
|
|
486
|
+
std_str = (
|
|
487
|
+
f"+/- {item['stdev_pct']:.1f}%" if item["stdev_pct"] is not None else "N/A"
|
|
488
|
+
)
|
|
489
|
+
std_str = std_str.rjust(std_width)
|
|
490
|
+
runs_str = f"({item['runs']} runs)"
|
|
491
|
+
runs_str = runs_str.rjust(runs_width)
|
|
492
|
+
|
|
493
|
+
print(f"| {name} | {avg_str} | {conf_str} | {std_str} | {runs_str} |")
|
|
494
|
+
|
|
495
|
+
# Footer
|
|
496
|
+
print(header)
|
|
497
|
+
|
|
498
|
+
# Calculate and display geometric mean if we have valid percentage changes
|
|
499
|
+
valid_percentages = [
|
|
500
|
+
item["avg_pct"] for item in summary_data if item["avg_pct"] is not None
|
|
501
|
+
]
|
|
502
|
+
|
|
503
|
+
if valid_percentages:
|
|
504
|
+
geo_mean = calculate_geometric_mean(valid_percentages)
|
|
505
|
+
if geo_mean is not None:
|
|
506
|
+
print(f"\nGeometric Mean of Changes: {geo_mean:+.1f}%")
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
# --- Main Script ---
|
|
510
|
+
if __name__ == "__main__":
|
|
511
|
+
parser = argparse.ArgumentParser(
|
|
512
|
+
description="Compare two benchmark implementations by running them multiple times.",
|
|
513
|
+
epilog='Example: %(prog)s -b "./old-exe -w -Xjit" -b "./new-exe -w -Xjit" benchmark1.js benchmark2.js',
|
|
514
|
+
)
|
|
515
|
+
parser.add_argument(
|
|
516
|
+
"-b",
|
|
517
|
+
"--binary",
|
|
518
|
+
action="append",
|
|
519
|
+
required=True,
|
|
520
|
+
help='Command to run (including arguments). Must be specified at least twice. Example: -b "./hermes -w -Xjit"',
|
|
521
|
+
metavar="COMMAND",
|
|
522
|
+
)
|
|
523
|
+
parser.add_argument(
|
|
524
|
+
"-n",
|
|
525
|
+
"--runs",
|
|
526
|
+
type=int,
|
|
527
|
+
default=1,
|
|
528
|
+
help="Number of times to run each benchmark (default: 1)",
|
|
529
|
+
)
|
|
530
|
+
parser.add_argument(
|
|
531
|
+
"-c",
|
|
532
|
+
"--confidence",
|
|
533
|
+
type=float,
|
|
534
|
+
default=0.95,
|
|
535
|
+
help="Confidence limit (default: 0.95)",
|
|
536
|
+
)
|
|
537
|
+
parser.add_argument(
|
|
538
|
+
"--percentage",
|
|
539
|
+
action="store_true",
|
|
540
|
+
help="Force percentage change display (default for 2 engines)",
|
|
541
|
+
)
|
|
542
|
+
parser.add_argument(
|
|
543
|
+
"--ratio",
|
|
544
|
+
action="store_true",
|
|
545
|
+
help="Force ratio display (default for 3+ engines)",
|
|
546
|
+
)
|
|
547
|
+
parser.add_argument(
|
|
548
|
+
"--compact",
|
|
549
|
+
action="store_true",
|
|
550
|
+
help="Hide detailed per-benchmark tables, show only summary tables",
|
|
551
|
+
)
|
|
552
|
+
parser.add_argument(
|
|
553
|
+
"--csv",
|
|
554
|
+
metavar="FILE",
|
|
555
|
+
help="Export results to CSV file for graphing (in addition to normal output)",
|
|
556
|
+
)
|
|
557
|
+
parser.add_argument(
|
|
558
|
+
"benchmarks",
|
|
559
|
+
metavar="BENCHMARK.JS",
|
|
560
|
+
nargs="+", # Require at least one benchmark file
|
|
561
|
+
help="Path to the benchmark file(s) to run.",
|
|
562
|
+
)
|
|
563
|
+
args = parser.parse_args()
|
|
564
|
+
|
|
565
|
+
# Validate at least two binaries
|
|
566
|
+
if len(args.binary) < 2:
|
|
567
|
+
print(
|
|
568
|
+
f"Error: At least two -b/--binary arguments required, got {len(args.binary)}.",
|
|
569
|
+
file=sys.stderr,
|
|
570
|
+
)
|
|
571
|
+
sys.exit(1)
|
|
572
|
+
|
|
573
|
+
if args.runs <= 0:
|
|
574
|
+
print("Error: Number of runs must be positive.", file=sys.stderr)
|
|
575
|
+
sys.exit(1)
|
|
576
|
+
|
|
577
|
+
# Parse the command strings into lists
|
|
578
|
+
engine_commands = [shlex.split(cmd) for cmd in args.binary]
|
|
579
|
+
num_engines = len(engine_commands)
|
|
580
|
+
|
|
581
|
+
# Determine display format
|
|
582
|
+
if args.percentage and args.ratio:
|
|
583
|
+
# Last one wins
|
|
584
|
+
display_format = "ratio" if args.ratio else "percentage"
|
|
585
|
+
elif args.percentage:
|
|
586
|
+
display_format = "percentage"
|
|
587
|
+
elif args.ratio:
|
|
588
|
+
display_format = "ratio"
|
|
589
|
+
else:
|
|
590
|
+
# Default behavior
|
|
591
|
+
display_format = "percentage" if num_engines == 2 else "ratio"
|
|
592
|
+
|
|
593
|
+
# Print engine commands
|
|
594
|
+
if num_engines == 2:
|
|
595
|
+
# Backward compatibility for 2 engines
|
|
596
|
+
print(f"OLD command: {' '.join(engine_commands[0])}")
|
|
597
|
+
print(f"NEW command: {' '.join(engine_commands[1])}")
|
|
598
|
+
else:
|
|
599
|
+
for i, cmd in enumerate(engine_commands):
|
|
600
|
+
print(f"Engine {i + 1} command: {' '.join(cmd)}")
|
|
601
|
+
print()
|
|
602
|
+
|
|
603
|
+
# Store summary results here
|
|
604
|
+
summary_results = []
|
|
605
|
+
|
|
606
|
+
# Store all results for multi-engine summary
|
|
607
|
+
all_benchmark_results = []
|
|
608
|
+
|
|
609
|
+
for filename in args.benchmarks:
|
|
610
|
+
print(f"--- Running benchmark: {filename} ({args.runs} runs) ---")
|
|
611
|
+
|
|
612
|
+
# Initialize data structures for multiple engines
|
|
613
|
+
engine_scores = defaultdict(list) # {engine_index: [scores]}
|
|
614
|
+
|
|
615
|
+
# Run benchmarks for all engines
|
|
616
|
+
for run_idx in range(args.runs):
|
|
617
|
+
for engine_idx, engine_cmd in enumerate(engine_commands):
|
|
618
|
+
# Determine display name for backward compatibility
|
|
619
|
+
if num_engines == 2:
|
|
620
|
+
engine_name = "OLD" if engine_idx == 0 else "NEW"
|
|
621
|
+
else:
|
|
622
|
+
engine_name = f"Engine {engine_idx + 1}"
|
|
623
|
+
|
|
624
|
+
print(f"{engine_name} {filename} (Run {run_idx + 1}/{args.runs})")
|
|
625
|
+
result = run_command(engine_cmd, filename)
|
|
626
|
+
print(result.stdout, end="")
|
|
627
|
+
score = find_first_score(result.stdout)
|
|
628
|
+
|
|
629
|
+
if score is not None:
|
|
630
|
+
engine_scores[engine_idx].append(score)
|
|
631
|
+
else:
|
|
632
|
+
print(
|
|
633
|
+
f"Warning: Score not found for {engine_name} {filename} run {run_idx + 1}/{args.runs}."
|
|
634
|
+
)
|
|
635
|
+
|
|
636
|
+
print("-" * 20) # Separator between runs
|
|
637
|
+
|
|
638
|
+
# Process results for this benchmark
|
|
639
|
+
benchmark_result = {"name": filename, "engines": []}
|
|
640
|
+
|
|
641
|
+
# Calculate statistics for each engine
|
|
642
|
+
baseline_avg = None
|
|
643
|
+
for engine_idx in range(num_engines):
|
|
644
|
+
scores = engine_scores[engine_idx]
|
|
645
|
+
if not scores:
|
|
646
|
+
continue
|
|
647
|
+
|
|
648
|
+
avg_score = statistics.mean(scores)
|
|
649
|
+
valid_runs = len(scores)
|
|
650
|
+
|
|
651
|
+
# Set baseline from first engine
|
|
652
|
+
if engine_idx == 0:
|
|
653
|
+
baseline_avg = avg_score
|
|
654
|
+
|
|
655
|
+
engine_data = {
|
|
656
|
+
"index": engine_idx,
|
|
657
|
+
"command": " ".join(engine_commands[engine_idx]),
|
|
658
|
+
"scores": scores,
|
|
659
|
+
"avg_score": avg_score,
|
|
660
|
+
"valid_runs": valid_runs,
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
# Calculate standard deviation if we have enough runs
|
|
664
|
+
if valid_runs >= 2:
|
|
665
|
+
try:
|
|
666
|
+
engine_data["stdev"] = statistics.stdev(scores)
|
|
667
|
+
except (statistics.StatisticsError, ValueError):
|
|
668
|
+
engine_data["stdev"] = None
|
|
669
|
+
else:
|
|
670
|
+
engine_data["stdev"] = None
|
|
671
|
+
|
|
672
|
+
# Calculate confidence interval
|
|
673
|
+
if engine_idx > 0 and valid_runs >= 2 and len(engine_scores[0]) >= 2:
|
|
674
|
+
(low, high) = manual_ttest_confidence_interval(
|
|
675
|
+
scores, engine_scores[0], args.confidence
|
|
676
|
+
)
|
|
677
|
+
if low is not None and high is not None and baseline_avg != 0:
|
|
678
|
+
engine_data["confidence_interval"] = (
|
|
679
|
+
baseline_avg + low,
|
|
680
|
+
baseline_avg + high,
|
|
681
|
+
)
|
|
682
|
+
else:
|
|
683
|
+
engine_data["confidence_interval"] = (None, None)
|
|
684
|
+
else:
|
|
685
|
+
engine_data["confidence_interval"] = (None, None)
|
|
686
|
+
|
|
687
|
+
# Calculate comparison to baseline
|
|
688
|
+
if baseline_avg and baseline_avg != 0:
|
|
689
|
+
engine_data["vs_baseline_ratio"] = avg_score / baseline_avg
|
|
690
|
+
engine_data["vs_baseline_pct"] = (
|
|
691
|
+
(avg_score - baseline_avg) / baseline_avg
|
|
692
|
+
) * 100
|
|
693
|
+
else:
|
|
694
|
+
engine_data["vs_baseline_ratio"] = None
|
|
695
|
+
engine_data["vs_baseline_pct"] = None
|
|
696
|
+
|
|
697
|
+
benchmark_result["engines"].append(engine_data)
|
|
698
|
+
|
|
699
|
+
all_benchmark_results.append(benchmark_result)
|
|
700
|
+
|
|
701
|
+
# For backward compatibility with 2 engines, maintain old summary format
|
|
702
|
+
if num_engines == 2 and len(benchmark_result["engines"]) >= 2:
|
|
703
|
+
engine0 = benchmark_result["engines"][0]
|
|
704
|
+
engine1 = benchmark_result["engines"][1]
|
|
705
|
+
|
|
706
|
+
if engine0["avg_score"] and engine0["avg_score"] != 0:
|
|
707
|
+
avg_percentage_change = engine1["vs_baseline_pct"]
|
|
708
|
+
|
|
709
|
+
# Calculate stdev of percentage changes
|
|
710
|
+
individual_pct_changes = []
|
|
711
|
+
for i in range(min(len(engine0["scores"]), len(engine1["scores"]))):
|
|
712
|
+
if engine0["scores"][i] != 0:
|
|
713
|
+
pct = (
|
|
714
|
+
(engine1["scores"][i] - engine0["scores"][i])
|
|
715
|
+
/ engine0["scores"][i]
|
|
716
|
+
) * 100
|
|
717
|
+
individual_pct_changes.append(pct)
|
|
718
|
+
|
|
719
|
+
if len(individual_pct_changes) >= 2:
|
|
720
|
+
try:
|
|
721
|
+
stdev_percentage_change = statistics.stdev(
|
|
722
|
+
individual_pct_changes
|
|
723
|
+
)
|
|
724
|
+
except (statistics.StatisticsError, ValueError):
|
|
725
|
+
stdev_percentage_change = None
|
|
726
|
+
else:
|
|
727
|
+
stdev_percentage_change = None
|
|
728
|
+
|
|
729
|
+
# Get confidence interval
|
|
730
|
+
conf_int = engine1.get("confidence_interval", (None, None))
|
|
731
|
+
if conf_int[0] is not None and engine0["avg_score"] != 0:
|
|
732
|
+
pct_low = (
|
|
733
|
+
(conf_int[0] - engine0["avg_score"])
|
|
734
|
+
/ engine0["avg_score"]
|
|
735
|
+
* 100
|
|
736
|
+
)
|
|
737
|
+
pct_high = (
|
|
738
|
+
(conf_int[1] - engine0["avg_score"])
|
|
739
|
+
/ engine0["avg_score"]
|
|
740
|
+
* 100
|
|
741
|
+
)
|
|
742
|
+
else:
|
|
743
|
+
pct_low, pct_high = None, None
|
|
744
|
+
|
|
745
|
+
change_output_line = format_change_line(
|
|
746
|
+
avg_percentage_change,
|
|
747
|
+
stdev_percentage_change,
|
|
748
|
+
len(individual_pct_changes),
|
|
749
|
+
)
|
|
750
|
+
print(f"Summary for {filename}: {change_output_line}")
|
|
751
|
+
|
|
752
|
+
# Store for legacy summary table
|
|
753
|
+
summary_results.append(
|
|
754
|
+
{
|
|
755
|
+
"name": filename,
|
|
756
|
+
"avg_pct": avg_percentage_change,
|
|
757
|
+
"stdev_pct": stdev_percentage_change,
|
|
758
|
+
"ttest": (pct_low, pct_high),
|
|
759
|
+
"runs": len(individual_pct_changes),
|
|
760
|
+
}
|
|
761
|
+
)
|
|
762
|
+
else:
|
|
763
|
+
print(f"Summary for {filename}: Change: N/A (baseline score is 0)")
|
|
764
|
+
summary_results.append(
|
|
765
|
+
{
|
|
766
|
+
"name": filename,
|
|
767
|
+
"avg_pct": None,
|
|
768
|
+
"stdev_pct": None,
|
|
769
|
+
"ttest": (None, None),
|
|
770
|
+
"runs": 0,
|
|
771
|
+
}
|
|
772
|
+
)
|
|
773
|
+
|
|
774
|
+
# Print detailed per-benchmark table for multi-engine case
|
|
775
|
+
if num_engines > 2 and not args.compact:
|
|
776
|
+
print_per_benchmark_table(benchmark_result, display_format, args.confidence)
|
|
777
|
+
|
|
778
|
+
print() # Empty line before next benchmark
|
|
779
|
+
|
|
780
|
+
# --- Print Final Summary Tables ---
|
|
781
|
+
print("=" * 60)
|
|
782
|
+
print("Overall Benchmark Summary")
|
|
783
|
+
print("=" * 60)
|
|
784
|
+
|
|
785
|
+
if num_engines == 2:
|
|
786
|
+
# Use legacy format for 2 engines
|
|
787
|
+
# 1. Table in Original Order
|
|
788
|
+
print_summary_table(
|
|
789
|
+
"Results (Original Order)", args.confidence, summary_results
|
|
790
|
+
)
|
|
791
|
+
|
|
792
|
+
# 2. Table Sorted by Average Change (Descending)
|
|
793
|
+
sorted_summary = sorted(
|
|
794
|
+
summary_results,
|
|
795
|
+
key=lambda item: item.get("avg_pct")
|
|
796
|
+
if item.get("avg_pct") is not None
|
|
797
|
+
else -math.inf,
|
|
798
|
+
reverse=True,
|
|
799
|
+
)
|
|
800
|
+
print_summary_table(
|
|
801
|
+
"Results (Sorted by Avg Change Descending)", args.confidence, sorted_summary
|
|
802
|
+
)
|
|
803
|
+
else:
|
|
804
|
+
# Use new compact format for 3+ engines
|
|
805
|
+
# 1. Summary in original order
|
|
806
|
+
print_compact_summary_table(
|
|
807
|
+
"Summary Results (Original Order)",
|
|
808
|
+
all_benchmark_results,
|
|
809
|
+
display_format,
|
|
810
|
+
num_engines,
|
|
811
|
+
sort_by_last=False,
|
|
812
|
+
)
|
|
813
|
+
|
|
814
|
+
# 2. Summary sorted by last engine
|
|
815
|
+
print_compact_summary_table(
|
|
816
|
+
f"Summary Results (Sorted by engine{num_engines}/engine1)",
|
|
817
|
+
all_benchmark_results,
|
|
818
|
+
display_format,
|
|
819
|
+
num_engines,
|
|
820
|
+
sort_by_last=True,
|
|
821
|
+
)
|
|
822
|
+
|
|
823
|
+
# Export to CSV if requested
|
|
824
|
+
if args.csv:
|
|
825
|
+
export_to_csv(args.csv, all_benchmark_results, engine_commands)
|
|
826
|
+
|
|
827
|
+
print("\nBenchmark Comparison Complete.")
|