Skip to content
Myr

plot_histogram.py

This file

Path

scripts/plot_histogram.py

40 lines · 1.1 KiB · Python

Last changed by

scripts: modify shebang to use "/usr/bin/env python"muxatorbefore adoption5a80a23

History of this file

Take it

scripts: modify shebang to use "/usr/bin/env python"muxatorbefore adoption5a80a23

line 1why, one step back
1#!/usr/bin/env python

Add a script to plot histogramssharkdpbefore adoptionef8a166

lines 2–6why, one step back
2
3"""This program shows `hyperfine` benchmark results as a histogram."""45import argparse6import json

Show the full range in histogramsDavid Peterbefore adoptiona3f0278

line 7why, one step back
7import numpy as np

Add a script to plot histogramssharkdpbefore adoptionef8a166

lines 8–12why, one step back
8import matplotlib.pyplot as plt
910parser = argparse.ArgumentParser(description=__doc__)11parser.add_argument("file", help="JSON file with benchmark results")12parser.add_argument("--title", help="Plot title")

plot_histogram.py: add --type and --binssharkdpbefore adoptiond441eef

lines 13–16why, one step back
13parser.add_argument("--bins", help="Number of bins (default: auto)")
14parser.add_argument(15 "--type", help="Type of histogram (*bar*, barstacked, step, stepfilled)"16)

Add a script to plot histogramssharkdpbefore adoptionef8a166

lines 17–24why, one step back
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]24

Fix computation of min/max time rangesharkdpbefore adoptiondab1da9

lines 25–27why, one step back
25t_min = np.min(list(map(np.min, all_times)))
26t_max = np.max(list(map(np.max, all_times)))27

plot_histogram.py: add --type and --binssharkdpbefore adoptiond441eef

lines 28–30why, one step back
28bins = int(args.bins) if args.bins else "auto"
29histtype = args.type if args.type else "bar"30

Auto-format Python scriptssharkdpbefore adoption8fff864

line 31why, one step back
31plt.hist(

plot_histogram.py: add --type and --binssharkdpbefore adoptiond441eef

line 32why, one step back
32 all_times, label=commands, bins=bins, histtype=histtype, range=(t_min, t_max),

Auto-format Python scriptssharkdpbefore adoption8fff864

lines 33–34why, one step back
33)
34plt.legend(prop={"family": ["Source Code Pro", "Fira Mono", "Courier New"]})

Add a script to plot histogramssharkdpbefore adoptionef8a166

lines 35–40why, one step back
35
36plt.xlabel("Time [s]")37if args.title:38 plt.title(args.title)3940plt.show()