Skip to content
Myr

Add plot_progression.py

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Peter · committed by David Peter · parent bcd3705 · Browse files · 2 files+64 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+64 added−0 removed

  • other:+64 added−0 removed

2 files+64 added−0 removed

added:scripts/plot_progression.py+62 added
1#!/usr/bin/env python23"""This program shows `hyperfine` benchmark results in a sequential way4in order to debug possible background interference, caching effects,5thermal throttling and similar effects.6"""78import argparse9import json10import matplotlib.pyplot as plt11import numpy as np121314def moving_average(times, num_runs):15 times_padded = np.pad(16 times, (num_runs // 2, num_runs - 1 - num_runs // 2), mode="edge"17 )18 kernel = np.ones(num_runs) / num_runs19 return np.convolve(times_padded, kernel, mode="valid")202122parser = argparse.ArgumentParser(description=__doc__)23parser.add_argument("file", help="JSON file with benchmark results")24parser.add_argument("--title", help="Plot Title")25parser.add_argument("-o", "--output", help="Save image to the given filename.")26parser.add_argument(27 "-w",28 "--moving-average-width",29 type=int,30 metavar="num_runs",31 help="Width of the moving-average window (default: N/5)",32)3334args = parser.parse_args()3536with open(args.file) as f:37 results = json.load(f)["results"]3839label = results[0]["command"]40times = results[0]["times"]41num = len(times)42nums = range(num)4344plt.scatter(x=nums, y=times, marker=".", color="orange")45plt.ylim([0, None])46plt.xlim([-1, num])4748moving_average_width = (49 num // 5 if args.moving_average_width is None else args.moving_average_width50)5152moving_average = moving_average(times, moving_average_width)53plt.plot(nums, moving_average, "-", color="blue")5455if args.title:56 plt.title(args.title)57plt.legend(labels=[label], loc="best", fontsize="medium")58plt.ylabel("Time [s]")59if args.output:60 plt.savefig(args.output)61else:62 plt.show()
modified:CHANGELOG.md+2 added
9 unmodified lines
10 (with a runtime on the order of a few milliseconds). See #336, #429,11 and #487 (@cipriancraciun and @sharkdp)12- Added `--setup` (`s`) option that can be used to run `make all` or13 similar. It runs once per set of tests, like `--cleanup` (`c`).14- Added new `plot_progression.py` script to debug background interference15 effects.1617## Changes1819- Breaking change: the `-s` short option for `--style` is now used for
278 unmodified lines