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 fileTake 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 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 serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
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 serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
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 serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
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 serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
line 19why, one step back19Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529
lines 20–24why, one step back20def 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 back25Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529
line 26why, one step back26 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 back27Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529
lines 28–29why, one step back28 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 back30Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529
lines 31–34why, one step back31 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 back35Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529
lines 36–38why, one step back36 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 back39Make plotting scripts runnable with uvDavid Peterbefore adoptionce49529
lines 40–59why, one step back40 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()