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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
#!/usr/bin/python3.6
import numpy as np # type: ignore
import matplotlib.pyplot as plt # type: ignore
import pandas as pd # type: ignore
import sys
from typing import *
##
# Reading data
##
if len(sys.argv) != 3:
raise Exception("Arguments for this script: the csv file, the base name of the output PDF file")
_, csv_file, output_basename = sys.argv
with open(csv_file, "r") as f:
df = pd.read_csv(csv_file)
benches = df["benches"]
host_measures_cols = [col for col in df if "host" in col]
k1c_measures_cols = [col for col in df if "k1c" in col]
colors = ["forestgreen", "darkorange", "cornflowerblue", "darkorchid", "darksalmon", "dodgerblue", "navy", "gray", "springgreen", "crimson"]
##
# Generating PDF
##
def extract_compiler(env: str) -> str:
words = env.split()[:-1]
return " ".join(words)
def extract_compilers(envs: List[str]) -> List[str]:
compilers: List[str] = []
for env in envs:
compiler = extract_compiler(env)
if compiler not in compilers:
compilers.append(compiler)
return compilers
def subdivide_interv(inf: Any, sup: float, n: int) -> List[float]:
return [inf + k*(sup-inf)/n for k in range(n)]
# df associates the environment string (e.g. "gcc host") to the cycles
# envs is the list of environments to compare
# The returned value will be a dictionnary associating the compiler (e.g. "gcc") to his relative comparison on the best result
def make_relative_heights(data: Dict[str, List[float]], envs: List[str]) -> Dict[str, List[float]]:
n_benches: int = len(data["benches"])
cols: Dict[str, List[float]] = {extract_compiler(env):data[env] for env in envs}
ret: Dict[str, List[float]] = {}
for compiler in cols:
ret[compiler] = []
for i in range(n_benches):
maximum: float = max([cols[compiler][i] for compiler in cols])
for compiler in cols:
ret[compiler].append(cols[compiler][i] / float(maximum))
return ret
def generate_file(f: str, cols: List[str]) -> None:
ind = np.arange(len(df[cols[0]]))
width = 0.25 # the width of the bars
compilers = extract_compilers(cols)
start_inds = subdivide_interv(ind, ind+2*width, len(compilers))
inverse_cycles = {key:[1./x if isinstance(x, int) else x for x in list(df[key])] for key in df.columns}
heights: Dict[str, List[float]] = make_relative_heights(inverse_cycles, cols)
fig, ax = plt.subplots()
rects = []
for i, compiler in enumerate(compilers):
rects.append(ax.bar(start_inds[i], heights[compiler], width, color=colors[i], label=compiler))
# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_ylabel('1/cycles (%)')
ax.set_yticklabels(['{:,.0%}'.format(x) for x in ax.get_yticks()])
ax.set_title('TITLE')
ax.set_xticks(ind)
ax.set_xticklabels(benches)
ax.legend()
plt.setp(ax.get_xticklabels(), rotation=30, horizontalalignment='right')
plt.xticks(size=5)
plt.savefig(f)
generate_file(output_basename + ".host.pdf", host_measures_cols)
generate_file(output_basename + ".k1c.pdf", k1c_measures_cols)
|