Add a script to plot histograms
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by sharkdp · committed by David Peter · parent b3084cb · Browse files · 3 files·+55 added−28 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+55 added−28 removed
- other:+55 added−28 removed
Provenance
- Commit
ef8a166- Tree
d3f748e- Author
sharkdp <davidpeter@web.de>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
b3084cb
3 files changed+55 added−28 removed
deleted:scripts/plot_benchmark_results.py-28 removed
1-#!/usr/bin/python2-3-"""This program shows `hyperfine` benchmark results as a box and whisker plot.4-5-Quoting from the matplotlib documentation:6- The box extends from the lower to upper quartile values of the data, with7- a line at the median. The whiskers extend from the box to show the range8- of the data. Flier points are those past the end of the whiskers.9-"""10-11-import argparse12-import json13-import matplotlib.pyplot as plt14-15-parser = argparse.ArgumentParser(description=__doc__)16-parser.add_argument("file", help="JSON file with benchmark results")17-args = parser.parse_args()18-19-with open(args.file) as f:20- results = json.load(f)["results"]21-22-commands = [b["command"] for b in results]23-times = [b["times"] for b in results]24-25-plt.boxplot(times, labels=commands)26-plt.ylabel("Time [s]")27-plt.ylim(0, None)28-plt.show()added:scripts/plot_histogram.py+27 added
1+#!/usr/bin/python2+3+"""This program shows `hyperfine` benchmark results as a histogram."""4+5+import argparse6+import json7+import matplotlib.pyplot as plt8+9+parser = argparse.ArgumentParser(description=__doc__)10+parser.add_argument("file", help="JSON file with benchmark results")11+parser.add_argument("--title", help="Plot title")12+args = parser.parse_args()13+14+with open(args.file) as f:15+ results = json.load(f)["results"]16+17+commands = [b["command"] for b in results]18+all_times = [b["times"] for b in results]19+20+plt.hist(all_times, label=commands, bins="auto", histtype="bar")21+plt.legend(prop={'family': ['Source Code Pro', 'Fira Mono', 'Courier New']})22+23+plt.xlabel("Time [s]")24+if args.title:25+ plt.title(args.title)26+27+plt.show()added:scripts/plot_whisker.py+28 added
1+#!/usr/bin/python2+3+"""This program shows `hyperfine` benchmark results as a box and whisker plot.4+5+Quoting from the matplotlib documentation:6+ The box extends from the lower to upper quartile values of the data, with7+ a line at the median. The whiskers extend from the box to show the range8+ of the data. Flier points are those past the end of the whiskers.9+"""10+11+import argparse12+import json13+import matplotlib.pyplot as plt14+15+parser = argparse.ArgumentParser(description=__doc__)16+parser.add_argument("file", help="JSON file with benchmark results")17+args = parser.parse_args()18+19+with open(args.file) as f:20+ results = json.load(f)["results"]21+22+commands = [b["command"] for b in results]23+times = [b["times"] for b in results]24+25+plt.boxplot(times, labels=commands)26+plt.ylabel("Time [s]")27+plt.ylim(0, None)28+plt.show()