2020-10-08 22:51:31 +02:00
|
|
|
#!/usr/bin/env python
|
2024-08-28 16:52:02 +02:00
|
|
|
# /// script
|
|
|
|
|
# requires-python = ">=3.10"
|
|
|
|
|
# dependencies = [
|
|
|
|
|
# "scipy",
|
|
|
|
|
# ]
|
|
|
|
|
# ///
|
2019-10-07 14:57:42 +09:00
|
|
|
|
2019-10-07 18:44:55 +02:00
|
|
|
"""This script performs Welch's t-test on a JSON export file with two
|
2026-10-02 11:50:42 +02:00
|
|
|
benchmark results to test for a difference in their population mean runtimes."""
|
2019-10-07 18:44:55 +02:00
|
|
|
|
2019-10-07 14:57:42 +09:00
|
|
|
import argparse
|
|
|
|
|
import json
|
2019-10-07 18:36:00 +02:00
|
|
|
import sys
|
2024-08-28 17:01:09 +02:00
|
|
|
|
2019-10-07 14:57:42 +09:00
|
|
|
from scipy import stats
|
|
|
|
|
|
2019-10-07 18:44:55 +02:00
|
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
2019-10-07 18:36:00 +02:00
|
|
|
parser.add_argument("file", help="JSON file with two benchmark results")
|
2019-10-07 14:57:42 +09:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
with open(args.file) as f:
|
|
|
|
|
results = json.load(f)["results"]
|
|
|
|
|
|
2019-10-07 18:36:00 +02:00
|
|
|
if len(results) != 2:
|
|
|
|
|
print("The input file has to contain exactly two benchmarks")
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
2026-10-05 18:11:10 +02:00
|
|
|
a, b = (x.get("name", x["command"]) for x in results[:2])
|
2026-10-05 16:59:35 +02:00
|
|
|
X, Y = ([m["time_wall_clock"]["value"] for m in x["measurements"]] for x in results[:2])
|
2019-10-07 14:57:42 +09:00
|
|
|
|
2024-08-28 16:41:58 +02:00
|
|
|
print(f"Command 1: {a}")
|
|
|
|
|
print(f"Command 2: {b}\n")
|
2019-10-07 14:57:42 +09:00
|
|
|
|
|
|
|
|
t, p = stats.ttest_ind(X, Y, equal_var=False)
|
|
|
|
|
th = 0.05
|
|
|
|
|
dispose = p < th
|
2024-08-28 16:41:58 +02:00
|
|
|
print(f"t = {t:.3}, p = {p:.3}")
|
2019-10-07 18:58:07 +02:00
|
|
|
print()
|
|
|
|
|
|
2019-10-07 14:57:42 +09:00
|
|
|
if dispose:
|
2026-10-02 11:50:42 +02:00
|
|
|
print(
|
|
|
|
|
f"A statistically significant difference in mean runtime was detected (p < {th})."
|
|
|
|
|
)
|
2019-10-07 14:57:42 +09:00
|
|
|
else:
|
2026-10-02 11:50:42 +02:00
|
|
|
print(
|
|
|
|
|
f"No statistically significant difference in mean runtime was detected (p >= {th})."
|
|
|
|
|
)
|