Skip to content
Myr

plot_parametrized.py

This file

Path

scripts/plot_parametrized.py

54 lines · 1.3 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 plot_parametrized.py scriptsharkdpbefore adoption0d22a96

lines 2–11why, one step back
2
3"""This program shows parametrized `hyperfine` benchmark results as an4errorbar plot."""56import argparse7import json8import matplotlib.pyplot as plt910parser = argparse.ArgumentParser(description=__doc__)11parser.add_argument("file", help="JSON file with benchmark results", nargs="+")

Auto-format Python scriptssharkdpbefore adoption8fff864

lines 12–17why, one step back
12parser.add_argument(
13 "--parameter-name",14 metavar="name",15 type=str,16 help="Name of the parameter / x-axis label",17)

Add --log-time and --log-x flagssharkdpbefore adoptionc649d8d

lines 18–23why, one step back
18parser.add_argument(
19 "--log-x", help="Use a logarithmic x (parameter) axis", action="store_true"20)21parser.add_argument(22 "--log-time", help="Use a logarithmic time axis", action="store_true"23)

Add --titles optionsharkdpbefore adoptionca81ab2

lines 24–26why, one step back
24parser.add_argument(
25 "--titles", help="Comma-separated list of titles for the plot legend"26)

Add --log-time and --log-x flagssharkdpbefore adoptionc649d8d

line 27why, one step back
27

Add plot_parametrized.py scriptsharkdpbefore adoption0d22a96

lines 28–37why, one step back
28args = parser.parse_args()
2930for filename in args.file:31 with open(filename) as f:32 results = json.load(f)["results"]3334 parameter_values = [float(b["parameter"]) for b in results]35 times_mean = [b["mean"] for b in results]36 times_stddev = [b["stddev"] for b in results]37

Auto-format Python scriptssharkdpbefore adoption8fff864

line 38why, one step back
38 plt.errorbar(x=parameter_values, y=times_mean, yerr=times_stddev, capsize=2)

Add plot_parametrized.py scriptsharkdpbefore adoption0d22a96

lines 39–41why, one step back
39
40plt.xlabel(args.parameter_name)41plt.ylabel("Time [s]")

Add --log-time and --log-x flagssharkdpbefore adoptionc649d8d

lines 42–49why, one step back
42
43if args.log_time:44 plt.yscale("log")45else:46 plt.ylim(0, None)4748if args.log_x:49 plt.xscale("log")

Add --titles optionsharkdpbefore adoptionca81ab2

lines 50–52why, one step back
50
51if args.titles:52 plt.legend(args.titles.split(","))

Add --log-time and --log-x flagssharkdpbefore adoptionc649d8d

line 53why, one step back
53

Add plot_parametrized.py scriptsharkdpbefore adoption0d22a96

line 54why, one step back
54plt.show()