plot_histogram.py
This file
Path
scripts/plot_histogram.py
40 lines · 1.1 KiB · Python
Last changed by
plot_histogram.py: add --type and --binssharkdpbefore adoptiond441eef
History of this fileTake it
1#!/usr/bin/python23"""This program shows `hyperfine` benchmark results as a histogram."""45import argparse6import json7import numpy as np8import matplotlib.pyplot as plt910parser = argparse.ArgumentParser(description=__doc__)11parser.add_argument("file", help="JSON file with benchmark results")12parser.add_argument("--title", help="Plot title")13parser.add_argument("--bins", help="Number of bins (default: auto)")14parser.add_argument(15 "--type", help="Type of histogram (*bar*, barstacked, step, stepfilled)"16)17args = parser.parse_args()1819with open(args.file) as f:20 results = json.load(f)["results"]2122commands = [b["command"] for b in results]23all_times = [b["times"] for b in results]2425t_min = np.min(list(map(np.min, all_times)))26t_max = np.max(list(map(np.max, all_times)))2728bins = int(args.bins) if args.bins else "auto"29histtype = args.type if args.type else "bar"3031plt.hist(32 all_times, label=commands, bins=bins, histtype=histtype, range=(t_min, t_max),33)34plt.legend(prop={"family": ["Source Code Pro", "Fira Mono", "Courier New"]})3536plt.xlabel("Time [s]")37if args.title:38 plt.title(args.title)3940plt.show()