welch_ttest.py
This file
Path
scripts/welch_ttest.py
38 lines · 1014 bytes · Python
Last changed by
Auto-format Python scriptssharkdpbefore adoption8fff864
History of this fileTake it
scripts: add welch's t testYasuaki Uechibefore adoption5a3fc3c
lines 1–2why, one step back1#!/usr/bin/python2Add help textsharkdpbefore adoptionc06f50d
lines 3–6why, one step back3"""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."""6scripts: add welch's t testYasuaki Uechibefore adoption5a3fc3c
lines 7–8why, one step back7import argparse8import jsonAdd error messagesharkdpbefore adoption071d5c6
line 9why, one step back9import sysscripts: add welch's t testYasuaki Uechibefore adoption5a3fc3c
lines 10–11why, one step back10from scipy import stats11Add help textsharkdpbefore adoptionc06f50d
line 12why, one step back12parser = argparse.ArgumentParser(description=__doc__)Add error messagesharkdpbefore adoption071d5c6
line 13why, one step back13parser.add_argument("file", help="JSON file with two benchmark results")scripts: add welch's t testYasuaki Uechibefore adoption5a3fc3c
lines 14–17why, one step back14args = parser.parse_args()1516with open(args.file) as f:17 results = json.load(f)["results"]Add error messagesharkdpbefore adoption071d5c6
lines 18–21why, one step back1819if len(results) != 2:20 print("The input file has to contain exactly two benchmarks")21 sys.exit(1)scripts: add welch's t testYasuaki Uechibefore adoption5a3fc3c
lines 22–31why, one step back2223a, 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 < thOutput formattingsharkdpbefore adoption94d458c
lines 32–34why, one step back32print("t = {:.3}, p = {:.3}".format(t, p))33print()34scripts: add welch's t testYasuaki Uechibefore adoption5a3fc3c
line 35why, one step back35if dispose:Auto-format Python scriptssharkdpbefore adoption8fff864
line 36why, one step back36 print("There is a difference between the two benchmarks (p < {}).".format(th))scripts: add welch's t testYasuaki Uechibefore adoption5a3fc3c
line 37why, one step back37else:Output formattingsharkdpbefore adoption94d458c
line 38why, one step back38 print("The two benchmarks are almost the same (p >= {}).".format(th))