welch_ttest.py
This file
Path
scripts/welch_ttest.py
48 lines · 1.1 KiB · Python
Last changed by
Correct the interpretation of Welch's t-test results (#943)David Peterbefore adoptionf6d5931
History of this fileTake it
The walk stopped after 200 commits: lines older than c44aa1d point at it.
Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
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 suggestionsDavid Peterbefore adoptionc44aa1d
lines 8–9why, one step back89"""This script performs Welch's t-test on a JSON export file with twoCorrect the interpretation of Welch's t-test results (#943)David Peterbefore adoptionf6d5931
line 10why, one step back10benchmark results to test for a difference in their population mean runtimes."""Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 11–14why, one step back1112import argparse13import json14import sysSort importsDavid Peterbefore adoptionbc37eff
line 15why, one step back15Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 16–28why, one step back16from scipy import stats1718parser = argparse.ArgumentParser(description=__doc__)19parser.add_argument("file", help="JSON file with two benchmark results")20args = parser.parse_args()2122with open(args.file) as f:23 results = json.load(f)["results"]2425if len(results) != 2:26 print("The input file has to contain exactly two benchmarks")27 sys.exit(1)28Update formatting, use f-stringsDavid Peterbefore adoption65dd84f
lines 29–30why, one step back29a, b = (x["command"] for x in results[:2])30X, Y = (x["times"] for x in results[:2])Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
line 31why, one step back31Update formatting, use f-stringsDavid Peterbefore adoption65dd84f
lines 32–33why, one step back32print(f"Command 1: {a}")33print(f"Command 2: {b}\n")Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 34–37why, one step back3435t, p = stats.ttest_ind(X, Y, equal_var=False)36th = 0.0537dispose = p < thUpdate formatting, use f-stringsDavid Peterbefore adoption65dd84f
line 38why, one step back38print(f"t = {t:.3}, p = {p:.3}")Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
lines 39–41why, one step back39print()4041if dispose:Correct the interpretation of Welch's t-test results (#943)David Peterbefore adoptionf6d5931
lines 42–44why, one step back42 print(43 f"A statistically significant difference in mean runtime was detected (p < {th})."44 )Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d
line 45why, one step back45else:Correct the interpretation of Welch's t-test results (#943)David Peterbefore adoptionf6d5931
lines 46–48why, one step back46 print(47 f"No statistically significant difference in mean runtime was detected (p >= {th})."48 )