Skip to content
Myr

plot_progression.py

This file

Path

scripts/plot_progression.py

94 lines · 2.4 KiB · Python

Last changed by

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

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# "pyqt6",6# "matplotlib",7# "numpy",8# ]9# ///

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

lines 10–17why, one step back
10
11"""This program shows `hyperfine` benchmark results in a sequential way12in order to debug possible background interference, caching effects,13thermal throttling and similar effects.14"""1516import argparse17import json

Sort importsDavid Peterbefore adoptionbc37eff

line 18why, one step back
18

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

lines 19–21why, one step back
19import matplotlib.pyplot as plt
20import numpy as np21

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

line 22why, one step back
22from plot_utils import METRICS, add_metric_argument, validate_metric

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

line 23why, one step back
23

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

lines 24–27why, one step back
24
25def moving_average(values, num_runs):26 values_padded = np.pad(27 values, (num_runs // 2, num_runs - 1 - num_runs // 2), mode="edge"

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

lines 28–29why, one step back
28 )
29 kernel = np.ones(num_runs) / num_runs

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

line 30why, one step back
30 return np.convolve(values_padded, kernel, mode="valid")

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

lines 31–33why, one step back
31
3233parser = argparse.ArgumentParser(description=__doc__)

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

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

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

lines 35–44why, one step back
35parser.add_argument("file", help="JSON file with benchmark results")
36parser.add_argument("--title", help="Plot Title")37parser.add_argument("-o", "--output", help="Save image to the given filename.")38parser.add_argument(39 "-w",40 "--moving-average-width",41 type=int,42 metavar="num_runs",43 help="Width of the moving-average window (default: N/5)",44)

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

lines 45–49why, one step back
45parser.add_argument(
46 "--no-moving-average",47 action="store_true",48 help="Do not show moving average curve",49)

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

line 50why, one step back
50

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

line 51why, one step back
51

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

line 52why, one step back
52args = parser.parse_args()

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

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

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

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

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

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

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

line 58why, one step back
58

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

line 59why, one step back
59for result in results:

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

line 60why, one step back
60 label = result.get("name", result["command"])

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

lines 61–62why, one step back
61 values = [m[args.metric]["value"] / metric_scale for m in result["measurements"]]
62 num = len(values)

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

line 63why, one step back
63 nums = range(num)

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

line 64why, one step back
64

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

line 65why, one step back
65 plt.scatter(x=nums, y=values, marker=".")

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

lines 66–67why, one step back
66 plt.ylim([0, None])
67 plt.xlim([-1, num])

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

line 68why, one step back
68

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

lines 69–70why, one step back
69 if not args.no_moving_average:
70 moving_average_width = (

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

lines 71–73why, one step back
71 max(1, num // 5)
72 if args.moving_average_width is None73 else args.moving_average_width

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

line 74why, one step back
74 )

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

line 75why, one step back
75

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

line 76why, one step back
76 average = moving_average(values, moving_average_width)

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

line 77why, one step back
77 plt.plot(nums, average, "-")

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

lines 78–80why, one step back
78
79if args.title:80 plt.title(args.title)

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

lines 81–83why, one step back
81
82legend = []83for result in results:

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

line 84why, one step back
84 legend.append(result.get("name", result["command"]))

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

lines 85–88why, one step back
85 if not args.no_moving_average:
86 legend.append("moving average")87plt.legend(legend)88

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

line 89why, one step back
89plt.ylabel(metric_label)

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

line 90why, one step back
90

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

lines 91–94why, one step back
91if args.output:
92 plt.savefig(args.output)93else:94 plt.show()