1#!/usr/bin/env python3 2 3# Copyright Hans Dembinski 2019 4# Distributed under the Boost Software License, Version 1.0. 5# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt 6 7from matplotlib import pyplot as plt, lines 8import shelve 9import json 10import subprocess as subp 11import sys 12from collections import defaultdict 13from run_benchmarks import get_commits, run 14import numpy as np 15import threading 16 17thread = None 18current_index = 0 19 20commits, comments = get_commits() 21 22def get_benchmarks(results): 23 benchmarks = defaultdict(lambda: []) 24 for hash in commits: 25 if hash in results and results[hash] is not None: 26 benchs = results[hash] 27 for b in benchs["benchmarks"]: 28 name = b["name"] 29 time = min(b["cpu_time"], b["real_time"]) 30 benchmarks[name].append((commits.index(hash), time)) 31 return benchmarks 32 33with shelve.open("benchmark_results") as results: 34 benchmarks = get_benchmarks(results) 35 36fig, ax = plt.subplots(4, 1, figsize=(10, 10), sharex=True) 37plt.subplots_adjust(hspace=0, top=0.98, bottom=0.05, right=0.96) 38 39plt.sca(ax[0]) 40for name, xy in benchmarks.items(): 41 if "uniform" in name: continue 42 if "_1d" in name: 43 x, y = np.transpose(xy) 44 plt.plot(x, y, ".-", label=name) 45plt.legend(fontsize="xx-small") 46 47plt.sca(ax[1]) 48for name, xy in benchmarks.items(): 49 if "uniform" in name: continue 50 if "_2d" in name: 51 x, y = np.transpose(xy) 52 plt.plot(x, y, ".-", label=name) 53plt.legend(fontsize="xx-small") 54 55plt.sca(ax[2]) 56for name, xy in benchmarks.items(): 57 if "uniform" in name: continue 58 if "_3d" in name: 59 x, y = np.transpose(xy) 60 plt.plot(x, y, ".-", label=name) 61plt.legend(fontsize="xx-small") 62 63plt.sca(ax[3]) 64for name, xy in benchmarks.items(): 65 if "uniform" in name: continue 66 if "_6d" in name: 67 x, y = np.transpose(xy) 68 plt.plot(x, y, ".-", label=name) 69plt.legend(fontsize="xx-small") 70 71plt.figtext(0.01, 0.5, "time per loop / ns [smaller is better]", rotation=90, va="center") 72 73def format_coord(x, y): 74 global current_index 75 current_index = max(0, min(int(x + 0.5), len(commits) - 1)) 76 hash = commits[current_index] 77 comment = comments[hash] 78 return f"{hash} {comment}" 79 80for axi in ax.flatten(): 81 axi.format_coord = format_coord 82 83def on_key_press(event): 84 global thread 85 if thread and thread.is_alive(): return 86 87 if event.key != "u": return 88 89 hash = commits[current_index] 90 91 def worker(fig, ax, hash): 92 with shelve.open("benchmark_results") as results: 93 run(results, comments, hash, True) 94 benchmarks = get_benchmarks(results) 95 96 for name in benchmarks: 97 xy = benchmarks[name] 98 x, y = np.transpose(xy) 99 for axi in ax.flatten(): 100 for artist in axi.get_children(): 101 if isinstance(artist, lines.Line2D) and artist.get_label() == name: 102 artist.set_xdata(x) 103 artist.set_ydata(y) 104 105 fig.canvas.draw() 106 107 thread = threading.Thread(target=worker, args=(fig, ax, hash)) 108 thread.start() 109 110fig.canvas.mpl_connect('key_press_event', on_key_press) 111 112plt.show() 113