Skip to content
Myr

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

3 files+55 added−28 removed

deleted:scripts/plot_benchmark_results.py-28 removed
1#!/usr/bin/python23"""This program shows `hyperfine` benchmark results as a box and whisker plot.45Quoting 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"""1011import argparse12import json13import matplotlib.pyplot as plt1415parser = argparse.ArgumentParser(description=__doc__)16parser.add_argument("file", help="JSON file with benchmark results")17args = parser.parse_args()1819with open(args.file) as f:20 results = json.load(f)["results"]2122commands = [b["command"] for b in results]23times = [b["times"] for b in results]2425plt.boxplot(times, labels=commands)26plt.ylabel("Time [s]")27plt.ylim(0, None)28plt.show()
added:scripts/plot_histogram.py+27 added
1#!/usr/bin/python23"""This program shows `hyperfine` benchmark results as a histogram."""45import argparse6import json7import matplotlib.pyplot as plt89parser = argparse.ArgumentParser(description=__doc__)10parser.add_argument("file", help="JSON file with benchmark results")11parser.add_argument("--title", help="Plot title")12args = parser.parse_args()1314with open(args.file) as f:15 results = json.load(f)["results"]1617commands = [b["command"] for b in results]18all_times = [b["times"] for b in results]1920plt.hist(all_times, label=commands, bins="auto", histtype="bar")21plt.legend(prop={'family': ['Source Code Pro', 'Fira Mono', 'Courier New']})2223plt.xlabel("Time [s]")24if args.title:25 plt.title(args.title)2627plt.show()
added:scripts/plot_whisker.py+28 added
1#!/usr/bin/python23"""This program shows `hyperfine` benchmark results as a box and whisker plot.45Quoting 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"""1011import argparse12import json13import matplotlib.pyplot as plt1415parser = argparse.ArgumentParser(description=__doc__)16parser.add_argument("file", help="JSON file with benchmark results")17args = parser.parse_args()1819with open(args.file) as f:20 results = json.load(f)["results"]2122commands = [b["command"] for b in results]23times = [b["times"] for b in results]2425plt.boxplot(times, labels=commands)26plt.ylabel("Time [s]")27plt.ylim(0, None)28plt.show()