Skip to content
Myr

plot_histogram.py

This file

Path

scripts/plot_histogram.py

128 lines · 2.9 KiB · Python

Last changed by

Support hardware counters in plotting scripts (#984)David Peterbefore adoptione262cd6

History of this file

Take it

The walk stopped after 200 commits: lines older than ab5ae5f point at it.

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

line 1why, one step back
1#!/usr/bin/env python

Add PEP-723 inline metadataDavid Peterbefore adoptioncfae9cb

lines 2–9why, one step back
2# /// script
3# requires-python = ">=3.10"4# dependencies = [5# "matplotlib",6# "pyqt6",7# "numpy",8# ]9# ///

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

lines 10–14why, one step back
10
11"""This program shows `hyperfine` benchmark results as a histogram."""1213import argparse14import json

Sort importsDavid Peterbefore adoptionbc37eff

line 15why, one step back
15

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

line 16why, one step back
16import matplotlib.pyplot as plt

Sort importsDavid Peterbefore adoptionbc37eff

line 17why, one step back
17import numpy as np

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

line 18why, one step back
18

Support all exported metrics in plotting scripts (#981)David Peterbefore adoptionef86c83

lines 19–20why, one step back
19from plot_utils import METRICS, add_metric_argument, validate_metric
20

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

line 21why, one step back
21parser = argparse.ArgumentParser(description=__doc__)

Support all exported metrics in plotting scripts (#981)David Peterbefore adoptionef86c83

line 22why, one step back
22add_metric_argument(parser)

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

lines 23–29why, one step back
23parser.add_argument("file", help="JSON file with benchmark results")
24parser.add_argument("--title", help="Plot title")25parser.add_argument(26 "--labels", help="Comma-separated list of entries for the plot legend"27)28parser.add_argument("--bins", help="Number of bins (default: auto)")29parser.add_argument(

Update formatting, use f-stringsDavid Peterbefore adoption65dd84f

lines 30–47why, one step back
30 "--legend-location",
31 help="Location of the legend on plot (default: upper center)",32 choices=[33 "upper center",34 "lower center",35 "right",36 "left",37 "best",38 "upper left",39 "upper right",40 "lower left",41 "lower right",42 "center left",43 "center right",44 "center",45 ],46 default="upper center",47)

add: legend modification parameters and output DPI (#758)Spreadcatbefore adoptionef9e140

line 48why, one step back
48parser.add_argument(

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

lines 49–52why, one step back
49 "--type", help="Type of histogram (*bar*, barstacked, step, stepfilled)"
50)51parser.add_argument("-o", "--output", help="Save image to the given filename.")52parser.add_argument(

Support all exported metrics in plotting scripts (#981)David Peterbefore adoptionef86c83

lines 53–56why, one step back
53 "--min",
54 "--t-min",55 dest="value_min",56 type=float,

Support hardware counters in plotting scripts (#984)David Peterbefore adoptione262cd6

line 57why, one step back
57 help="Minimum metric value to display",

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

lines 58–59why, one step back
58)
59parser.add_argument(

Support all exported metrics in plotting scripts (#981)David Peterbefore adoptionef86c83

lines 60–63why, one step back
60 "--max",
61 "--t-max",62 dest="value_max",63 type=float,

Support hardware counters in plotting scripts (#984)David Peterbefore adoptione262cd6

line 64why, one step back
64 help="Maximum metric value to display",

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

lines 65–72why, one step back
65)
66parser.add_argument(67 "--log-count",68 help="Use a logarithmic y-axis for the event count",69 action="store_true",70)7172args = parser.parse_args()

Support all exported metrics in plotting scripts (#981)David Peterbefore adoptionef86c83

line 73why, one step back
73metric_label, metric_scale = METRICS[args.metric]

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

lines 74–76why, one step back
74
75with open(args.file) as f:76 results = json.load(f)["results"]

Support all exported metrics in plotting scripts (#981)David Peterbefore adoptionef86c83

line 77why, one step back
77validate_metric(parser, results, args.metric)

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

lines 78–81why, one step back
78
79if args.labels:80 labels = args.labels.split(",")81else:

Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015

line 82why, one step back
82 labels = [b.get("name", b["command"]) for b in results]

Support all exported metrics in plotting scripts (#981)David Peterbefore adoptionef86c83

lines 83–84why, one step back
83all_values = [
84 [m[args.metric]["value"] / metric_scale for m in b["measurements"]] for b in results

Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015

line 85why, one step back
85]

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

line 86why, one step back
86

Support all exported metrics in plotting scripts (#981)David Peterbefore adoptionef86c83

lines 87–96why, one step back
87value_min = (
88 args.value_min89 if args.value_min is not None90 else np.min(list(map(np.min, all_values)))91)92value_max = (93 args.value_max94 if args.value_max is not None95 else np.max(list(map(np.max, all_values)))96)

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

lines 97–100why, one step back
97
98bins = int(args.bins) if args.bins else "auto"99histtype = args.type if args.type else "bar"100

add: legend modification parameters and output DPI (#758)Spreadcatbefore adoptionef9e140

line 101why, one step back
101plt.figure(figsize=(10, 5))

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

line 102why, one step back
102plt.hist(

Support all exported metrics in plotting scripts (#981)David Peterbefore adoptionef86c83

line 103why, one step back
103 all_values,

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

lines 104–106why, one step back
104 label=labels,
105 bins=bins,106 histtype=histtype,

Support all exported metrics in plotting scripts (#981)David Peterbefore adoptionef86c83

line 107why, one step back
107 range=(value_min, value_max),

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

line 108why, one step back
108)

add: legend modification parameters and output DPI (#758)Spreadcatbefore adoptionef9e140

line 109why, one step back
109plt.legend(

Update formatting, use f-stringsDavid Peterbefore adoption65dd84f

lines 110–114why, one step back
110 loc=args.legend_location,
111 fancybox=True,112 shadow=True,113 prop={"size": 10, "family": ["Source Code Pro", "Fira Mono", "Courier New"]},114)

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

line 115why, one step back
115

Support all exported metrics in plotting scripts (#981)David Peterbefore adoptionef86c83

line 116why, one step back
116plt.xlabel(metric_label)

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

lines 117–125why, one step back
117if args.title:
118 plt.title(args.title)119120if args.log_count:121 plt.yscale("log")122else:123 plt.ylim(0, None)124125if args.output:

add: legend modification parameters and output DPI (#758)Spreadcatbefore adoptionef9e140

line 126why, one step back
126 plt.savefig(args.output, dpi=600)

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

lines 127–128why, one step back
127else:
128 plt.show()