From 00ae0b645d3d3e1cbf8f8f81560f22ae2bd1278c Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Tue, 21 May 2019 15:18:43 +0200 Subject: Better graphs --- test/monniaux/gengraphs.py | 78 ++++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 37 deletions(-) (limited to 'test') diff --git a/test/monniaux/gengraphs.py b/test/monniaux/gengraphs.py index fd8098b7..3ffe6f3d 100755 --- a/test/monniaux/gengraphs.py +++ b/test/monniaux/gengraphs.py @@ -18,7 +18,6 @@ with open(csv_file, "r") as f: df = pd.read_csv(csv_file) benches = df["benches"] -print(benches[0]) host_measures_cols = [col for col in df if "host" in col] k1c_measures_cols = [col for col in df if "k1c" in col] @@ -29,62 +28,67 @@ colors = ["forestgreen", "darkorange", "cornflowerblue", "darkorchid", "darksalm # Generating PDF ## -def extract_envs(keys: List[str]) -> List[str]: - envs = [] - for key in keys: - words = key.split()[:-1] - envs.append(" ".join(words)) - return envs +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: float, sup: float, n: int) -> List[float]: +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: Any, envs: List[str]) -> Dict[str, List[float]]: + n_benches: int = len((data.values)) # type: ignore + cols: Dict[str, List[int]] = {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): + max_time: int = max([cols[compiler][i] for compiler in cols]) + for compiler in cols: + ret[compiler].append(cols[compiler][i] / float(max_time)) + + return ret + + def generate_file(f: str, cols: List[str]) -> None: ind = np.arange(len(df[cols[0]])) - width = 0.35 # the width of the bars + width = 0.25 # the width of the bars - envs = extract_envs(cols) - start_inds = subdivide_interv(ind, ind+width, len(envs)) + compilers = extract_compilers(cols) + start_inds = subdivide_interv(ind, ind+2*width, len(compilers)) + heights: Dict[str, List[float]] = make_relative_heights(df, cols) fig, ax = plt.subplots() rects = [] - for i, env in enumerate(envs): - for col in cols: - if env in col: - break - rects.append(ax.bar(start_inds[i], df[col], width, color=colors[i], label=env)) + 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('Cycles') + ax.set_ylabel('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() - def autolabel(rects: List[Any], xpos='center') -> None: - """ - Attach a text label above each bar in *rects*, displaying its height. - - *xpos* indicates which side to place the text w.r.t. the center of - the bar. It can be one of the following {'center', 'right', 'left'}. - """ - - xpos = xpos.lower() # normalize the case of the parameter - ha = {'center': 'center', 'right': 'left', 'left': 'right'} - offset = {'center': 0.5, 'right': 0.57, 'left': 0.43} # x_txt = x + w*off - - for rect in rects: - height = rect.get_height() - ax.text(rect.get_x() + rect.get_width()*offset[xpos], 1.01*height, - '{}'.format(height), ha=ha[xpos], va='bottom') - - for rect in rects: - autolabel(rect) + plt.setp(ax.get_xticklabels(), rotation=30, horizontalalignment='right') + plt.xticks(size=5) plt.savefig(f) generate_file("measures-host.pdf", host_measures_cols) -#generate_file("measures-k1c.pdf", k1c_measures_cols) +generate_file("measures-k1c.pdf", k1c_measures_cols) -- cgit