Skip to content
Myr

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 file

Take 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 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# ///

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

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

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

line 10why, one step back
10benchmark 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 back
11
12import argparse

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

line 13why, one step back
13import math

Sort importsDavid Peterbefore adoptionbc37eff

line 14why, one step back
14

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

lines 15–16why, one step back
15from scipy import stats
16

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

lines 17–18why, one step back
17from plot_utils import METRICS, add_metric_argument, load_results
18

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

lines 19–20why, one step back
19parser = 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 back
21add_metric_argument(parser)

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

lines 22–23why, one step back
22args = parser.parse_args()
23

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

line 24why, one step back
24metric, [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 back
25
26if len(results) != 2:

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

line 27why, one step back
27 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 back
28

Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015

line 29why, one step back
29a, 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 back
30X, 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 back
33

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

line 34why, one step back
34print(f"Metric: {METRICS[metric].label}")

Update formatting, use f-stringsDavid Peterbefore adoption65dd84f

lines 35–36why, one step back
35print(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 back
37
38t, p = stats.ttest_ind(X, Y, equal_var=False)

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

lines 39–40why, one step back
39if 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 back
41th = 0.05
42dispose = p < th

Update formatting, use f-stringsDavid Peterbefore adoption65dd84f

line 43why, one step back
43print(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 back
44print()
4546if dispose:

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

line 47why, one step back
47 print(

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

line 48why, one step back
48 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 back
49 )

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

line 50why, one step back
50else:

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

line 51why, one step back
51 print(

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

line 52why, one step back
52 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 back
53 )