Skip to content
Myr

plot_progression.py

This file

Path

scripts/plot_progression.py

89 lines · 2.1 KiB · Python

Last changed by

Refine JSON schema and command metadataDavid Peterbefore adoption0d86e78

History of this file

Take it

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

Add --conclude option with testsJack O'Connorbefore adoptione13d0cb

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# ///

Add --conclude option with testsJack O'Connorbefore adoptione13d0cb

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

Add --conclude option with testsJack O'Connorbefore adoptione13d0cb

lines 19–41why, one step back
19import matplotlib.pyplot as plt
20import numpy as np212223def moving_average(times, num_runs):24 times_padded = np.pad(25 times, (num_runs // 2, num_runs - 1 - num_runs // 2), mode="edge"26 )27 kernel = np.ones(num_runs) / num_runs28 return np.convolve(times_padded, kernel, mode="valid")293031parser = argparse.ArgumentParser(description=__doc__)32parser.add_argument("file", help="JSON file with benchmark results")33parser.add_argument("--title", help="Plot Title")34parser.add_argument("-o", "--output", help="Save image to the given filename.")35parser.add_argument(36 "-w",37 "--moving-average-width",38 type=int,39 metavar="num_runs",40 help="Width of the moving-average window (default: N/5)",41)

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

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

Add --conclude option with testsJack O'Connorbefore adoptione13d0cb

line 47why, one step back
47

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

line 48why, one step back
48

Add --conclude option with testsJack O'Connorbefore adoptione13d0cb

lines 49–53why, one step back
49args = parser.parse_args()
5051with open(args.file) as f:52 results = json.load(f)["results"]53

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

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

Refine JSON schema and command metadataDavid Peterbefore adoption0d86e78

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

Export metric summaries and adapt analysis scriptsDavid Peterbefore adoption1b3ec92

line 56why, one step back
56 times = [m["time_wall_clock"]["value"] for m in result["measurements"]]

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

lines 57–58why, one step back
57 num = len(times)
58 nums = range(num)

Add --conclude option with testsJack O'Connorbefore adoptione13d0cb

line 59why, one step back
59

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

lines 60–62why, one step back
60 plt.scatter(x=nums, y=times, marker=".")
61 plt.ylim([0, None])62 plt.xlim([-1, num])

Add --conclude option with testsJack O'Connorbefore adoptione13d0cb

line 63why, one step back
63

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

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

Export metric summaries and adapt analysis scriptsDavid Peterbefore adoption1b3ec92

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

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

line 69why, one step back
69 )

Add --conclude option with testsJack O'Connorbefore adoptione13d0cb

line 70why, one step back
70

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

lines 71–72why, one step back
71 average = moving_average(times, moving_average_width)
72 plt.plot(nums, average, "-")

Add --conclude option with testsJack O'Connorbefore adoptione13d0cb

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

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

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

Refine JSON schema and command metadataDavid Peterbefore adoption0d86e78

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

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

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

Add --conclude option with testsJack O'Connorbefore adoptione13d0cb

line 84why, one step back
84plt.ylabel("Time [s]")

Improve plot_progression.py scriptDavid Peterbefore adoptionc7be935

line 85why, one step back
85

Add --conclude option with testsJack O'Connorbefore adoptione13d0cb

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