import matplotlib.pyplot as plt import numpy as np import scipy.stats import subprocess # Names of branches to compare. BRANCHES = ["base", "alt"] # Total number of runs for each branch. RUNS = 250 # Initial runs to discard (50 is probably excessive here) SKIP = 50 # Get the timings values = {branch: [] for branch in BRANCHES} for i, branch in enumerate(BRANCHES * RUNS): subprocess.run(["git", "checkout", branch], check=True, capture_output=True) subprocess.run(["make"], check=True, capture_output=True) res = subprocess.run(f"./python.exe timecomb.py", shell=True, capture_output=True, encoding="utf-8") value = float(res.stdout) values[branch].append(value) print(f"{branch:4s} {i//2}: {value:.3f}ns") base = values["base"][SKIP:] alt = values["alt"][SKIP:] # Plot of the timings plt.plot(base, label="base") plt.plot(alt, label="alt") plt.xlabel("Run index") plt.ylabel("Time (ns)") plt.legend() plt.show() # Show percent speedup for alt over base. print(f"Mean time for base: {np.mean(base):.3f}ns") print(f"Mean for alt: {np.mean(alt):.3f}ns") speedup_factor = np.mean(base) / np.mean(alt) print(f"Speedup: {speedup_factor - 1.0:.2%}") # t-test for the hypothesis that the means are different print(scipy.stats.ttest_ind(base, alt))