3 # Copyright Hans Dembinski 2018 - 2019.
4 # Distributed under the Boost Software License, Version 1.0.
5 # (See accompanying file LICENSE_1_0.txt or copy at
6 # https://www.boost.org/LICENSE_1_0.txt)
14 from collections import defaultdict, OrderedDict
15 from matplotlib.patches import Rectangle
16 from matplotlib.lines import Line2D
17 from matplotlib.text import Text
18 from matplotlib.font_manager import FontProperties
19 import matplotlib.pyplot as plt
20 import matplotlib as mpl
22 mpl.rcParams.update(mpl.rcParamsDefault)
26 data = defaultdict(lambda: [])
27 for fn in sys.argv[1:]:
28 d = json.load(open(fn))
29 cpu_frequency = d["context"]["mhz_per_cpu"]
30 for bench in d["benchmarks"]:
32 time = min(bench["cpu_time"], bench["real_time"])
33 m = re.match("fill_(n_)?([0-9])d<([^>]+)>", name)
36 tags = m.group(3).split(", ")
39 "fill_([a-z]+)", os.path.splitext(os.path.split(fn)[1])[0]
42 if len(tags) > 1 and tags[1] in ("dynamic_tag", "static_tag"):
43 if len(tags) == 3 and "DStore" in tags[2]:
45 label += "-" + {"dynamic_tag": "dyn", "static_tag": "sta"}[tags[1]]
46 label += "-fill" if m.group(1) else "-call"
47 data[dim].append((label, dist, time / dim))
49 time_per_cycle_in_ns = 1.0 / (cpu_frequency * 1e6) / 1e-9
51 plt.figure(figsize=(7, 6))
53 for dim in sorted(data):
55 labels = OrderedDict()
56 for label, dist, time in v:
58 labels[label][dist] = time / time_per_cycle_in_ns
60 labels[label] = {dist: time / time_per_cycle_in_ns}
62 for label, d in labels.items():
66 z = float(j) / len(labels)
67 col = (1.0 - z) * np.array((1.0, 0.0, 0.0)) + z * np.array((1.0, 1.0, 0.0))
78 r1 = Rectangle((0, i), tmax, 1, facecolor=col)
80 (tmin, i), tmax - tmin, 1, facecolor="none", edgecolor="w", hatch="//////"
82 plt.gca().add_artist(r1)
83 plt.gca().add_artist(r2)
84 font = FontProperties(size=9)
94 plt.gca().add_artist(tx)
97 font = FontProperties()
98 font.set_weight("bold")
108 plt.gca().add_artist(tx)
112 plt.tick_params("y", left=False, labelleft=False)
113 plt.xlabel("average CPU cycles per random input value (smaller is better)")
117 plt.savefig("fill_performance.svg")