mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-10-28 16:18:57 +00:00
Make plotting scripts runnable with uv
This commit is contained in:
1 parent
4a9e066b41
commit
ce49529780
10 files changed
+526
-434
No files matched your search
@@ -21,65 +21,71 @@ import numpy as np
|
||||
|
||||
from plot_utils import METRICS, add_metric_argument, load_results
|
||||
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
add_metric_argument(parser)
|
||||
parser.add_argument(
|
||||
"files", nargs="+", type=pathlib.Path, help="JSON files with benchmark results"
|
||||
)
|
||||
parser.add_argument("--title", help="Plot Title")
|
||||
parser.add_argument(
|
||||
"--benchmark-names", nargs="+", help="Names of the benchmark groups"
|
||||
)
|
||||
parser.add_argument("-o", "--output", help="Save image to the given filename")
|
||||
|
||||
args = parser.parse_args()
|
||||
metric, datasets = load_results(parser, args.files, args.metric)
|
||||
metric_info = METRICS[metric]
|
||||
|
||||
commands = None
|
||||
data = []
|
||||
inputs = []
|
||||
|
||||
if args.benchmark_names:
|
||||
assert len(args.files) == len(args.benchmark_names), (
|
||||
"Number of benchmark names must match the number of input files."
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
add_metric_argument(parser)
|
||||
parser.add_argument(
|
||||
"files", nargs="+", type=pathlib.Path, help="JSON files with benchmark results"
|
||||
)
|
||||
parser.add_argument("--title", help="Plot Title")
|
||||
parser.add_argument(
|
||||
"--benchmark-names", nargs="+", help="Names of the benchmark groups"
|
||||
)
|
||||
parser.add_argument("-o", "--output", help="Save image to the given filename")
|
||||
|
||||
args = parser.parse_args()
|
||||
metric, datasets = load_results(parser, args.files, args.metric)
|
||||
metric_info = METRICS[metric]
|
||||
|
||||
commands = None
|
||||
data = []
|
||||
inputs = []
|
||||
|
||||
for i, (filename, results) in enumerate(zip(args.files, datasets)):
|
||||
benchmark_commands = [b.get("name", b["command"]) for b in results]
|
||||
if commands is None:
|
||||
commands = benchmark_commands
|
||||
else:
|
||||
assert commands == benchmark_commands, (
|
||||
f"Unexpected commands in {filename}: {benchmark_commands}, expected: {commands}"
|
||||
)
|
||||
data.append([b["summary"][metric]["mean"] / metric_info.scale for b in results])
|
||||
if args.benchmark_names:
|
||||
inputs.append(args.benchmark_names[i])
|
||||
assert len(args.files) == len(args.benchmark_names), (
|
||||
"Number of benchmark names must match the number of input files."
|
||||
)
|
||||
|
||||
for i, (filename, results) in enumerate(zip(args.files, datasets)):
|
||||
benchmark_commands = [b.get("name", b["command"]) for b in results]
|
||||
if commands is None:
|
||||
commands = benchmark_commands
|
||||
else:
|
||||
assert commands == benchmark_commands, (
|
||||
f"Unexpected commands in {filename}: {benchmark_commands}, expected: {commands}"
|
||||
)
|
||||
data.append([b["summary"][metric]["mean"] / metric_info.scale for b in results])
|
||||
if args.benchmark_names:
|
||||
inputs.append(args.benchmark_names[i])
|
||||
else:
|
||||
inputs.append(filename.stem)
|
||||
|
||||
data = np.transpose(data)
|
||||
x = np.arange(len(inputs)) # the label locations
|
||||
width = 0.25 # the width of the bars
|
||||
|
||||
fig, ax = plt.subplots(layout="constrained")
|
||||
fig.set_figheight(5)
|
||||
fig.set_figwidth(10)
|
||||
for i, command in enumerate(commands):
|
||||
offset = width * (i + 1)
|
||||
ax.bar(x + offset, data[i], width, label=command)
|
||||
|
||||
ax.set_xticks(x + 0.5, inputs)
|
||||
ax.grid(visible=True, axis="y")
|
||||
|
||||
if args.title:
|
||||
plt.title(args.title)
|
||||
plt.xlabel("Benchmark")
|
||||
plt.ylabel(metric_info.axis_label)
|
||||
plt.legend(title="Command")
|
||||
|
||||
if args.output:
|
||||
plt.savefig(args.output)
|
||||
else:
|
||||
inputs.append(filename.stem)
|
||||
plt.show()
|
||||
|
||||
data = np.transpose(data)
|
||||
x = np.arange(len(inputs)) # the label locations
|
||||
width = 0.25 # the width of the bars
|
||||
|
||||
fig, ax = plt.subplots(layout="constrained")
|
||||
fig.set_figheight(5)
|
||||
fig.set_figwidth(10)
|
||||
for i, command in enumerate(commands):
|
||||
offset = width * (i + 1)
|
||||
rects = ax.bar(x + offset, data[i], width, label=command)
|
||||
|
||||
ax.set_xticks(x + 0.5, inputs)
|
||||
ax.grid(visible=True, axis="y")
|
||||
|
||||
if args.title:
|
||||
plt.title(args.title)
|
||||
plt.xlabel("Benchmark")
|
||||
plt.ylabel(metric_info.axis_label)
|
||||
plt.legend(title="Command")
|
||||
|
||||
if args.output:
|
||||
plt.savefig(args.output)
|
||||
else:
|
||||
plt.show()
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user