Address comments
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Martin Liska · committed by David Peter · parent ee4e4d0 · Browse files · 2 files·+83 added−80 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+83 added−80 removed
- other:+83 added−80 removed
Provenance
- Commit
3cedcc3- Tree
2cb8941- Author
Martin Liska <martin.liska@hey.com>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
ee4e4d0
2 files changed+83 added−80 removed
added:scripts/plot_benchmark_comparison.py+83 added
1+#!/usr/bin/env python2+# /// script3+# requires-python = ">=3.10"4+# dependencies = [5+# "matplotlib",6+# "pyqt6",7+# "numpy",8+# ]9+# ///10+11+"""12+This script shows `hyperfine` benchmark results as a bar plot grouped by command.13+Note all the input files must contain results for all commands.14+"""15+16+import argparse17+import json18+import pathlib19+20+import matplotlib.pyplot as plt21+import numpy as np22+23+parser = argparse.ArgumentParser(description=__doc__)24+parser.add_argument(25+ "files", nargs="+", type=pathlib.Path, help="JSON files with benchmark results"26+)27+parser.add_argument("--title", help="Plot Title")28+parser.add_argument(29+ "--benchmark-names", nargs="+", help="Names of the benchmark groups"30+)31+parser.add_argument("-o", "--output", help="Save image to the given filename")32+33+args = parser.parse_args()34+35+commands = None36+data = []37+inputs = []38+39+if args.benchmark_names:40+ assert len(args.files) == len(41+ args.benchmark_names42+ ), "Number of benchmark names must match the number of input files."43+44+for i, filename in enumerate(args.files):45+ with open(filename) as f:46+ results = json.load(f)["results"]47+ benchmark_commands = [b["command"] for b in results]48+ if commands is None:49+ commands = benchmark_commands50+ else:51+ assert (52+ commands == benchmark_commands53+ ), f"Unexpected commands in {filename}: {benchmark_commands}, expected: {commands}"54+ data.append([round(b["mean"], 2) for b in results])55+ if args.benchmark_names:56+ inputs.append(args.benchmark_names[i])57+ else:58+ inputs.append(filename.stem)59+60+data = np.transpose(data)61+x = np.arange(len(inputs)) # the label locations62+width = 0.25 # the width of the bars63+64+fig, ax = plt.subplots(layout="constrained")65+fig.set_figheight(5)66+fig.set_figwidth(10)67+for i, command in enumerate(commands):68+ offset = width * (i + 1)69+ rects = ax.bar(x + offset, data[i], width, label=command)70+71+ax.set_xticks(x + 0.5, inputs)72+ax.grid(visible=True, axis="y")73+74+if args.title:75+ plt.title(args.title)76+plt.xlabel("Benchmark")77+plt.ylabel("Time [s]")78+plt.legend(title="Command")79+80+if args.output:81+ plt.savefig(args.output)82+else:83+ plt.show()deleted:scripts/plot_benchmarks.py-80 removed
1-#!/usr/bin/env python2-# /// script3-# requires-python = ">=3.10"4-# dependencies = [5-# "matplotlib",6-# "pyqt6",7-# "numpy",8-# ]9-# ///10-11-# This program shows `hyperfine` benchmark results as a bar plot grouped by command.12-13-import argparse14-import json15-import pathlib16-17-import matplotlib.pyplot as plt18-import numpy as np19-20-parser = argparse.ArgumentParser(description=__doc__)21-parser.add_argument(22- "files", nargs="+", type=pathlib.Path, help="JSON files with benchmark results"23-)24-parser.add_argument("--title", help="Plot Title")25-parser.add_argument(26- "--benchmark-names", nargs="+", help="Names of the benchmark groups"27-)28-parser.add_argument("-o", "--output", help="Save image to the given filename")29-30-args = parser.parse_args()31-32-commands = None33-data = []34-inputs = []35-36-if args.benchmark_names:37- assert len(args.files) == len(38- args.benchmark_names39- ), "Number of benchmark names must match the number of input files."40-41-for i, filename in enumerate(args.files):42- with open(filename) as f:43- results = json.load(f)["results"]44- benchmark_commands = [b["command"] for b in results]45- if commands is None:46- commands = benchmark_commands47- else:48- assert (49- commands == benchmark_commands50- ), f"Unexpected commands in {filename}: {benchmark_commands}, expected: {commands}"51- data.append([round(b["mean"], 2) for b in results])52- if args.benchmark_names:53- inputs.append(args.benchmark_names[i])54- else:55- inputs.append(filename.stem)56-57-data = np.transpose(data)58-x = np.arange(len(inputs)) # the label locations59-width = 0.25 # the width of the bars60-61-fig, ax = plt.subplots(layout="constrained")62-fig.set_figheight(5)63-fig.set_figwidth(10)64-for i, command in enumerate(commands):65- offset = width * (i + 1)66- rects = ax.bar(x + offset, data[i], width, label=command)67-68-ax.set_xticks(x + 0.5, inputs)69-ax.grid(visible=True, axis="y")70-71-if args.title:72- plt.title(args.title)73-plt.xlabel("Benchmark")74-plt.ylabel("Time [s]")75-plt.legend(title="Command")76-77-if args.output:78- plt.savefig(args.output)79-else:80- plt.show()