welch_ttest.py
This file
Path
scripts/welch_ttest.py
53 lines · 1.5 KiB · Python
Last changed by
Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
History of this fileTake it
The walk stopped after 200 commits: lines older than ab5ae5f point at it.
Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
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# ///Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 8–9why, one step back89"""This script performs Welch's t-test on a JSON export file with twoAlternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 10why, one step back10benchmark results to test for a difference in their population means."""Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 11–12why, one step back1112import argparseAlternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 13why, one step back13import mathSort importsDavid Peterbefore adoptionbc37eff
line 14why, one step back14Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 15–16why, one step back15from scipy import stats16Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 17–18why, one step back17from plot_utils import METRICS, add_metric_argument, load_results18Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 19–20why, one step back19parser = argparse.ArgumentParser(description=__doc__)20parser.add_argument("file", help="JSON file with two benchmark results")Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 21why, one step back21add_metric_argument(parser)Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 22–23why, one step back22args = parser.parse_args()23Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 24why, one step back24metric, [results] = load_results(parser, [args.file], args.metric)Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 25–26why, one step back2526if len(results) != 2:Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 27why, one step back27 parser.error("the input file must contain exactly two benchmarks")Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
line 28why, one step back28Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
line 29why, one step back29a, b = (x.get("name", x["command"]) for x in results[:2])Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 30–32why, one step back30X, Y = ([m[metric]["value"] for m in x["measurements"]] for x in results[:2])31if min(len(X), len(Y)) < 2:32 parser.error("Welch's t-test requires at least two measurements per benchmark")Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
line 33why, one step back33Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 34why, one step back34print(f"Metric: {METRICS[metric].label}")Update formatting, use f-stringsDavid Peterbefore adoption65dd84f
lines 35–36why, one step back35print(f"Command 1: {a}")36print(f"Command 2: {b}\n")Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 37–38why, one step back3738t, p = stats.ttest_ind(X, Y, equal_var=False)Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 39–40why, one step back39if not math.isfinite(p):40 parser.error("Welch's t-test is undefined for these measurements")Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 41–42why, one step back41th = 0.0542dispose = p < thUpdate formatting, use f-stringsDavid Peterbefore adoption65dd84f
line 43why, one step back43print(f"t = {t:.3}, p = {p:.3}")Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 44–46why, one step back44print()4546if dispose:Correct the interpretation of Welch's t-test results (#943)David Peterbefore adoptionf6d5931
line 47why, one step back47 print(Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 48why, one step back48 f"A statistically significant difference in mean value was detected (p < {th})."Correct the interpretation of Welch's t-test results (#943)David Peterbefore adoptionf6d5931
line 49why, one step back49 )Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
line 50why, one step back50else:Correct the interpretation of Welch's t-test results (#943)David Peterbefore adoptionf6d5931
line 51why, one step back51 print(Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 52why, one step back52 f"No statistically significant difference in mean value was detected (p >= {th})."Correct the interpretation of Welch's t-test results (#943)David Peterbefore adoptionf6d5931
line 53why, one step back53 )