plot_histogram.py
This file
Path
scripts/plot_histogram.py
53 lines · 1.4 KiB · Python
Last changed by
Change parameter name in plotting scriptsBenjamin Rosemannbefore adoption49fcc4b
History of this fileTake it
The walk stopped after 200 commits: lines older than 538691e point at it.
scripts: modify shebang to use "/usr/bin/env python"muxatorbefore adoption5a80a23
line 1why, one step back1#!/usr/bin/env pythonUse String instead of NumericType for paramater in CommandHasan Ibraheembefore adoption538691e
lines 2–6why, one step back23"""This program shows `hyperfine` benchmark results as a histogram."""45import argparse6import jsonShow the full range in histogramsDavid Peterbefore adoptiona3f0278
line 7why, one step back7import numpy as npUse String instead of NumericType for paramater in CommandHasan Ibraheembefore adoption538691e
lines 8–12why, one step back8import 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")Add parameters to plotting scriptsBenjamin Rosemannbefore adoptionb04a9ec
lines 13–15why, one step back13parser.add_argument(14 "--labels", help="Comma-separated list of entries for the plot legend"15)plot_histogram.py: add --type and --binssharkdpbefore adoptiond441eef
lines 16–19why, one step back16parser.add_argument("--bins", help="Number of bins (default: auto)")17parser.add_argument(18 "--type", help="Type of histogram (*bar*, barstacked, step, stepfilled)"19)Change parameter name in plotting scriptsBenjamin Rosemannbefore adoption49fcc4b
lines 20–23why, one step back20parser.add_argument(21 "-o", "--output", help="Save image to the given filename."22)23Use String instead of NumericType for paramater in CommandHasan Ibraheembefore adoption538691e
lines 24–28why, one step back24args = parser.parse_args()2526with open(args.file) as f:27 results = json.load(f)["results"]28Add parameters to plotting scriptsBenjamin Rosemannbefore adoptionb04a9ec
lines 29–32why, one step back29if args.labels:30 labels = args.labels.split(",")31else:32 labels = [b["command"] for b in results]Use String instead of NumericType for paramater in CommandHasan Ibraheembefore adoption538691e
lines 33–34why, one step back33all_times = [b["times"] for b in results]34Fix computation of min/max time rangesharkdpbefore adoptiondab1da9
lines 35–37why, one step back35t_min = np.min(list(map(np.min, all_times)))36t_max = np.max(list(map(np.max, all_times)))37plot_histogram.py: add --type and --binssharkdpbefore adoptiond441eef
lines 38–40why, one step back38bins = int(args.bins) if args.bins else "auto"39histtype = args.type if args.type else "bar"40Auto-format Python scriptssharkdpbefore adoption8fff864
line 41why, one step back41plt.hist(Add parameters to plotting scriptsBenjamin Rosemannbefore adoptionb04a9ec
line 42why, one step back42 all_times, label=labels, bins=bins, histtype=histtype, range=(t_min, t_max),Auto-format Python scriptssharkdpbefore adoption8fff864
lines 43–44why, one step back43)44plt.legend(prop={"family": ["Source Code Pro", "Fira Mono", "Courier New"]})Use String instead of NumericType for paramater in CommandHasan Ibraheembefore adoption538691e
lines 45–49why, one step back4546plt.xlabel("Time [s]")47if args.title:48 plt.title(args.title)49Change parameter name in plotting scriptsBenjamin Rosemannbefore adoption49fcc4b
lines 50–51why, one step back50if args.output:51 plt.savefig(args.output)Add parameters to plotting scriptsBenjamin Rosemannbefore adoptionb04a9ec
lines 52–53why, one step back52else:53 plt.show()