Skip to content
Myr

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 file

Take it

The walk stopped after 200 commits: lines older than c44aa1d point at it.

Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d

line 1why, one step back
1#!/usr/bin/env python

Add PEP-723 inline metadataDavid Peterbefore adoptioncfae9cb

lines 2–7why, one step back
2# /// script
3# requires-python = ">=3.10"4# dependencies = [5# "scipy",6# ]7# ///

Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d

lines 8–9why, one step back
8
9"""This script performs Welch's t-test on a JSON export file with two

Correct the interpretation of Welch's t-test results (#943)David Peterbefore adoptionf6d5931

line 10why, one step back
10benchmark results to test for a difference in their population mean runtimes."""

Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d

lines 11–14why, one step back
11
12import argparse13import json14import sys

Sort importsDavid Peterbefore adoptionbc37eff

line 15why, one step back
15

Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d

lines 16–28why, one step back
16from scipy import stats
1718parser = 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)28

Update formatting, use f-stringsDavid Peterbefore adoption65dd84f

lines 29–30why, one step back
29a, 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 back
31

Update formatting, use f-stringsDavid Peterbefore adoption65dd84f

lines 32–33why, one step back
32print(f"Command 1: {a}")
33print(f"Command 2: {b}\n")

Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d

lines 34–37why, one step back
34
35t, p = stats.ttest_ind(X, Y, equal_var=False)36th = 0.0537dispose = p < th

Update formatting, use f-stringsDavid Peterbefore adoption65dd84f

line 38why, one step back
38print(f"t = {t:.3}, p = {p:.3}")

Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d

lines 39–41why, one step back
39print()
4041if dispose:

Correct the interpretation of Welch's t-test results (#943)David Peterbefore adoptionf6d5931

lines 42–44why, one step back
42 print(
43 f"A statistically significant difference in mean runtime was detected (p < {th})."44 )

Fix clippy suggestionsDavid Peterbefore adoptionc44aa1d

line 45why, one step back
45else:

Correct the interpretation of Welch's t-test results (#943)David Peterbefore adoptionf6d5931

lines 46–48why, one step back
46 print(
47 f"No statistically significant difference in mean runtime was detected (p >= {th})."48 )