Skip to content
Myr

welch_ttest.py

This file

Path

scripts/welch_ttest.py

38 lines · 1018 bytes · Python

Last changed by

Not known.

History of this file

Take it

1#!/usr/bin/env python23"""This script performs Welch's t-test on a JSON export file with two4benchmark results to test whether or not the two distributions are5the same."""67import argparse8import json9import sys10from scipy import stats1112parser = argparse.ArgumentParser(description=__doc__)13parser.add_argument("file", help="JSON file with two benchmark results")14args = parser.parse_args()1516with open(args.file) as f:17    results = json.load(f)["results"]1819if len(results) != 2:20    print("The input file has to contain exactly two benchmarks")21    sys.exit(1)2223a, b = [x["command"] for x in results[:2]]24X, Y = [x["times"] for x in results[:2]]2526print("Command 1: {}".format(a))27print("Command 2: {}\n".format(b))2829t, p = stats.ttest_ind(X, Y, equal_var=False)30th = 0.0531dispose = p < th32print("t = {:.3}, p = {:.3}".format(t, p))33print()3435if dispose:36    print("There is a difference between the two benchmarks (p < {}).".format(th))37else:38    print("The two benchmarks are almost the same (p >= {}).".format(th))