Skip to content
Myr

plot_progression.py

This file

Path

scripts/plot_progression.py

90 lines · 2.3 KiB · Python

Last changed by

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

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–16why, 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 argparse

Sort importsDavid Peterbefore adoptionbc37eff

line 17why, one step back
17

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

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

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

line 21why, one step back
21from plot_utils import METRICS, add_metric_argument, load_results

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

line 22why, one step back
22

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

lines 23–26why, one step back
23
24def moving_average(values, num_runs):25 values_padded = np.pad(26 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 27–28why, one step back
27 )
28 kernel = np.ones(num_runs) / num_runs

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

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

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

lines 30–32why, one step back
30
3132parser = argparse.ArgumentParser(description=__doc__)

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

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

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

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

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

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

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

line 49why, one step back
49

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

line 50why, one step back
50

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

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

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

lines 52–53why, one step back
52metric, [results] = load_results(parser, [args.file], args.metric)
53metric_info = METRICS[metric]

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

line 54why, one step back
54

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

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

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

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

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

line 57why, one step back
57 values = [m[metric]["value"] / metric_info.scale for m in result["measurements"]]

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

line 58why, one step back
58 num = len(values)

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

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

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

line 60why, one step back
60

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

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

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

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

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

line 64why, one step back
64

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

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

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

lines 67–69why, one step back
67 max(1, num // 5)
68 if args.moving_average_width is None69 else args.moving_average_width

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

line 70why, one step back
70 )

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

line 71why, one step back
71

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

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

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

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

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

lines 74–76why, one step back
74
75if args.title:76 plt.title(args.title)

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

lines 77–79why, one step back
77
78legend = []79for result in results:

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

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

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

lines 81–84why, one step back
81 if not args.no_moving_average:
82 legend.append("moving average")83plt.legend(legend)84

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

line 85why, one step back
85plt.ylabel(metric_info.axis_label)

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

line 86why, one step back
86

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

lines 87–90why, one step back
87if args.output:
88 plt.savefig(args.output)89else:90 plt.show()