Skip to content
Myr

welch_ttest.py

This file

Path

scripts/welch_ttest.py

59 lines · 1.6 KiB · Python

Last changed by

Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529

History of this file

Take it

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

Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

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 serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

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 serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

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 serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

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 serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

line 19why, one step back
19

Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529

lines 20–24why, one step back
20def main():
21 parser = argparse.ArgumentParser(description=__doc__)22 parser.add_argument("file", help="JSON file with two benchmark results")23 add_metric_argument(parser)24 args = parser.parse_args()

Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

line 25why, one step back
25

Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529

line 26why, one step back
26 metric, [results] = load_results(parser, [args.file], args.metric)

Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

line 27why, one step back
27

Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529

lines 28–29why, one step back
28 if len(results) != 2:
29 parser.error("the input file must contain exactly two benchmarks")

Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

line 30why, one step back
30

Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529

lines 31–34why, one step back
31 a, b = (x.get("name", x["command"]) for x in results[:2])
32 X, Y = ([m[metric]["value"] for m in x["measurements"]] for x in results[:2])33 if min(len(X), len(Y)) < 2:34 parser.error("Welch's t-test requires at least two measurements per benchmark")

Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

line 35why, one step back
35

Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529

lines 36–38why, one step back
36 print(f"Metric: {METRICS[metric].label}")
37 print(f"Command 1: {a}")38 print(f"Command 2: {b}\n")

Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

line 39why, one step back
39

Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529

lines 40–59why, one step back
40 t, p = stats.ttest_ind(X, Y, equal_var=False)
41 if not math.isfinite(p):42 parser.error("Welch's t-test is undefined for these measurements")43 th = 0.0544 dispose = p < th45 print(f"t = {t:.3}, p = {p:.3}")46 print()4748 if dispose:49 print(50 f"A statistically significant difference in mean value was detected (p < {th})."51 )52 else:53 print(54 f"No statistically significant difference in mean value was detected (p >= {th})."55 )565758if __name__ == "__main__":59 main()