Repository navigation
Expand file tree
/
Copy pathplot_binary_sizes.py
More file actions
executable file
·76 lines (63 loc) · 2.38 KB
/
Copy pathplot_binary_sizes.py
File metadata and controls
executable file
·76 lines (63 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
# /// script
# requires-python = ">=3.10"
# dependencies = [
# "matplotlib",
# "pyqt6",
# "numpy",
# ]
# ///
"""
Script that generates a chart comparing the binary sizes of asyncify and wasmfx benchmarks.
Usage:
`python3 plot_binary_sizes.py results_binary_sizes.json --benchmarks itersum -o results_dir`
"""
import argparse
import json
import pathlib
import matplotlib.pyplot as plt
import numpy as np
# deal with inputs
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--benchmarks", nargs="*", help="List of benchmarks to run (sieve, itersum, treesum)")
parser.add_argument("files", type=pathlib.Path, help="JSON files with binary sizes")
parser.add_argument("-o", "--output", help="Save image to the given filename")
args = parser.parse_args()
benches = args.benchmarks
with open(args.files) as f:
data = json.load(f)
# The data should be a json of shape {"benchmark": str, "wasmfx": int, "asyncify": int}
# We will now remove the "benchmark" field because we already have the benchmark names in the `benches` variable,
# and stick the "wasmfx" and "asyncify" fields into a numpy array for easier manipulation
data = np.array([[entry["wasmfx"], entry["asyncify"]] for entry in data])
# Get the chart data: divide first column by second column to obtain wasmfx / asyncify ratio
ratio = np.divide(data[:, 1], data[:, 0])
# The width of the bars in the chart
width = 1
# Hope this is colourblind-friendly enough for sam
bar_colors = ['tab:blue', 'tab:orange', 'tab:cyan', 'tab:red', 'tab:purple', 'tab:brown', 'tab:pink', 'tab:gray']
# x-values for bar locations
bar_loc = np.arange(len(benches))
# Plot the data
fig, ax = plt.subplots()
for i in range(len(ratio)):
ax.bar(bar_loc[i], ratio[i], width, label=benches[i], color=bar_colors[i])
ax.set_xticks(bar_loc, benches)
ax.grid(visible=True, axis="y")
plt.title(f"Benchmark binary size comparison (Asyncify size / WasmFX size)")
plt.xlabel("Benchmark")
plt.ylabel("Size Ratio")
plt.legend(benches, bbox_to_anchor=(1.3, 1), loc="upper right")
# Add a horizontal line at y=1 to indicate where wasmfx and asyncify have equal performance
plt.axhline(
y=1.0,
color = 'r',
linestyle = '--',
linewidth = 3,
label = 'WasmFX = Asyncify'
)
# Export figure
if args.output:
plt.savefig(f"{args.output}/relative/relative_binary_sizes", bbox_inches="tight")
else:
plt.show()