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
+104
-97
@@ -17,108 +17,115 @@ 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("file", help="JSON file with benchmark results")
|
||||
parser.add_argument("--title", help="Plot title")
|
||||
parser.add_argument(
|
||||
"--labels", help="Comma-separated list of entries for the plot legend"
|
||||
)
|
||||
parser.add_argument("--bins", help="Number of bins (default: auto)")
|
||||
parser.add_argument(
|
||||
"--legend-location",
|
||||
help="Location of the legend on plot (default: upper center)",
|
||||
choices=[
|
||||
"upper center",
|
||||
"lower center",
|
||||
"right",
|
||||
"left",
|
||||
"best",
|
||||
"upper left",
|
||||
"upper right",
|
||||
"lower left",
|
||||
"lower right",
|
||||
"center left",
|
||||
"center right",
|
||||
"center",
|
||||
],
|
||||
default="upper center",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--type", help="Type of histogram (*bar*, barstacked, step, stepfilled)"
|
||||
)
|
||||
parser.add_argument("-o", "--output", help="Save image to the given filename.")
|
||||
parser.add_argument(
|
||||
"--min",
|
||||
"--t-min",
|
||||
dest="value_min",
|
||||
type=float,
|
||||
help="Minimum metric value to display",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--max",
|
||||
"--t-max",
|
||||
dest="value_max",
|
||||
type=float,
|
||||
help="Maximum metric value to display",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--log-count",
|
||||
help="Use a logarithmic y-axis for the event count",
|
||||
action="store_true",
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
metric, [results] = load_results(parser, [args.file], args.metric)
|
||||
metric_info = METRICS[metric]
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
add_metric_argument(parser)
|
||||
parser.add_argument("file", help="JSON file with benchmark results")
|
||||
parser.add_argument("--title", help="Plot title")
|
||||
parser.add_argument(
|
||||
"--labels", help="Comma-separated list of entries for the plot legend"
|
||||
)
|
||||
parser.add_argument("--bins", help="Number of bins (default: auto)")
|
||||
parser.add_argument(
|
||||
"--legend-location",
|
||||
help="Location of the legend on plot (default: upper center)",
|
||||
choices=[
|
||||
"upper center",
|
||||
"lower center",
|
||||
"right",
|
||||
"left",
|
||||
"best",
|
||||
"upper left",
|
||||
"upper right",
|
||||
"lower left",
|
||||
"lower right",
|
||||
"center left",
|
||||
"center right",
|
||||
"center",
|
||||
],
|
||||
default="upper center",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--type", help="Type of histogram (*bar*, barstacked, step, stepfilled)"
|
||||
)
|
||||
parser.add_argument("-o", "--output", help="Save image to the given filename.")
|
||||
parser.add_argument(
|
||||
"--min",
|
||||
"--t-min",
|
||||
dest="value_min",
|
||||
type=float,
|
||||
help="Minimum metric value to display",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--max",
|
||||
"--t-max",
|
||||
dest="value_max",
|
||||
type=float,
|
||||
help="Maximum metric value to display",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--log-count",
|
||||
help="Use a logarithmic y-axis for the event count",
|
||||
action="store_true",
|
||||
)
|
||||
|
||||
if args.labels:
|
||||
labels = args.labels.split(",")
|
||||
else:
|
||||
labels = [b.get("name", b["command"]) for b in results]
|
||||
all_values = [
|
||||
[m[metric]["value"] / metric_info.scale for m in b["measurements"]] for b in results
|
||||
]
|
||||
args = parser.parse_args()
|
||||
metric, [results] = load_results(parser, [args.file], args.metric)
|
||||
metric_info = METRICS[metric]
|
||||
|
||||
value_min = (
|
||||
args.value_min
|
||||
if args.value_min is not None
|
||||
else np.min(list(map(np.min, all_values)))
|
||||
)
|
||||
value_max = (
|
||||
args.value_max
|
||||
if args.value_max is not None
|
||||
else np.max(list(map(np.max, all_values)))
|
||||
)
|
||||
if args.labels:
|
||||
labels = args.labels.split(",")
|
||||
else:
|
||||
labels = [b.get("name", b["command"]) for b in results]
|
||||
all_values = [
|
||||
[m[metric]["value"] / metric_info.scale for m in b["measurements"]]
|
||||
for b in results
|
||||
]
|
||||
|
||||
bins = int(args.bins) if args.bins else "auto"
|
||||
histtype = args.type if args.type else "bar"
|
||||
value_min = (
|
||||
args.value_min
|
||||
if args.value_min is not None
|
||||
else np.min(list(map(np.min, all_values)))
|
||||
)
|
||||
value_max = (
|
||||
args.value_max
|
||||
if args.value_max is not None
|
||||
else np.max(list(map(np.max, all_values)))
|
||||
)
|
||||
|
||||
plt.figure(figsize=(10, 5))
|
||||
plt.hist(
|
||||
all_values,
|
||||
label=labels,
|
||||
bins=bins,
|
||||
histtype=histtype,
|
||||
range=(value_min, value_max),
|
||||
)
|
||||
plt.legend(
|
||||
loc=args.legend_location,
|
||||
fancybox=True,
|
||||
shadow=True,
|
||||
prop={"size": 10, "family": ["Source Code Pro", "Fira Mono", "Courier New"]},
|
||||
)
|
||||
bins = int(args.bins) if args.bins else "auto"
|
||||
histtype = args.type if args.type else "bar"
|
||||
|
||||
plt.xlabel(metric_info.axis_label)
|
||||
if args.title:
|
||||
plt.title(args.title)
|
||||
plt.figure(figsize=(10, 5))
|
||||
plt.hist(
|
||||
all_values,
|
||||
label=labels,
|
||||
bins=bins,
|
||||
histtype=histtype,
|
||||
range=(value_min, value_max),
|
||||
)
|
||||
plt.legend(
|
||||
loc=args.legend_location,
|
||||
fancybox=True,
|
||||
shadow=True,
|
||||
prop={"size": 10, "family": ["Source Code Pro", "Fira Mono", "Courier New"]},
|
||||
)
|
||||
|
||||
if args.log_count:
|
||||
plt.yscale("log")
|
||||
else:
|
||||
plt.ylim(0, None)
|
||||
plt.xlabel(metric_info.axis_label)
|
||||
if args.title:
|
||||
plt.title(args.title)
|
||||
|
||||
if args.output:
|
||||
plt.savefig(args.output, dpi=600)
|
||||
else:
|
||||
plt.show()
|
||||
if args.log_count:
|
||||
plt.yscale("log")
|
||||
else:
|
||||
plt.ylim(0, None)
|
||||
|
||||
if args.output:
|
||||
plt.savefig(args.output, dpi=600)
|
||||
else:
|
||||
plt.show()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user