welch_ttest.py
This file
Path
scripts/welch_ttest.py
45 lines · 1.0 KiB · Python
Last changed by
Sort importsDavid Peterbefore adoptionbc37eff
History of this fileTake it
The walk stopped after 200 commits: lines older than ec43213 point at it.
Fix clippy warningsDavid Peterbefore adoptionec43213
line 1why, one step back1#!/usr/bin/env pythonAdd PEP-723 inline metadataDavid Peterbefore adoptioncfae9cb
lines 2–7why, one step back2# /// script3# requires-python = ">=3.10"4# dependencies = [5# "scipy",6# ]7# ///Fix clippy warningsDavid Peterbefore adoptionec43213
lines 8–15why, one step back89"""This script performs Welch's t-test on a JSON export file with two10benchmark results to test whether or not the two distributions are11the same."""1213import argparse14import json15import sysSort importsDavid Peterbefore adoptionbc37eff
line 16why, one step back16Fix clippy warningsDavid Peterbefore adoptionec43213
lines 17–29why, one step back17from scipy import stats1819parser = argparse.ArgumentParser(description=__doc__)20parser.add_argument("file", help="JSON file with two benchmark results")21args = parser.parse_args()2223with open(args.file) as f:24 results = json.load(f)["results"]2526if len(results) != 2:27 print("The input file has to contain exactly two benchmarks")28 sys.exit(1)29Update formatting, use f-stringsDavid Peterbefore adoption65dd84f
lines 30–31why, one step back30a, b = (x["command"] for x in results[:2])31X, Y = (x["times"] for x in results[:2])Fix clippy warningsDavid Peterbefore adoptionec43213
line 32why, one step back32Update formatting, use f-stringsDavid Peterbefore adoption65dd84f
lines 33–34why, one step back33print(f"Command 1: {a}")34print(f"Command 2: {b}\n")Fix clippy warningsDavid Peterbefore adoptionec43213
lines 35–38why, one step back3536t, p = stats.ttest_ind(X, Y, equal_var=False)37th = 0.0538dispose = p < thUpdate formatting, use f-stringsDavid Peterbefore adoption65dd84f
line 39why, one step back39print(f"t = {t:.3}, p = {p:.3}")Fix clippy warningsDavid Peterbefore adoptionec43213
lines 40–42why, one step back40print()4142if dispose:Update formatting, use f-stringsDavid Peterbefore adoption65dd84f
line 43why, one step back43 print(f"There is a difference between the two benchmarks (p < {th}).")Fix clippy warningsDavid Peterbefore adoptionec43213
line 44why, one step back44else:Update formatting, use f-stringsDavid Peterbefore adoption65dd84f
line 45why, one step back45 print(f"The two benchmarks are almost the same (p >= {th}).")