Skip to content

Instantly share code, notes, and snippets.

@kendhia
Created March 18, 2023 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kendhia/f803fb804d3da2d5a91acce1fe218209 to your computer and use it in GitHub Desktop.
Save kendhia/f803fb804d3da2d5a91acce1fe218209 to your computer and use it in GitHub Desktop.
import json
import sys
import matplotlib.pyplot as plt
def get_test_name(test):
try:
return test["name"].split("/")[-1].split(".")[0]
except:
return test["name"]
def load_results(file_name):
with open(file_name, "r") as f:
return json.load(f)
def compare_results(results1, results2, results3):
test_names = sorted([get_test_name(test) for test in results1])
execution_times1 = []
execution_times2 = []
execution_times3 = []
for (index, value) in enumerate(results1):
execution_times1.append(float(results1[index]["metrics"]["exec_time"]))
execution_times2.append(float(results2[index]["metrics"]["exec_time"]))
execution_times3.append(float(results3[index]["metrics"]["exec_time"]))
return test_names, execution_times1, execution_times2, execution_times3
def plot_comparison(
compiler_name,
benchmark_name,
test_names,
execution_times1,
execution_times2,
execution_times3,
output_file,
):
fig, ax = plt.subplots(figsize=(10, 5))
index = list(range(len(test_names)))
bar_width = 0.35
rects1 = ax.bar(
index, execution_times1, bar_width, label=f"{benchmark_name} Configuration 1"
)
rects2 = ax.bar(
[i + bar_width for i in index],
execution_times2,
bar_width,
label=f"{benchmark_name} Configuration 2",
)
rects3 = ax.bar(
[i + (bar_width * 2) for i in index],
execution_times3,
bar_width,
label=f"{benchmark_name} Configuration 3",
)
ax.set_xlabel("Test Name")
ax.set_ylabel("Execution Time")
ax.set_title(f"{benchmark_name} Comparison of Execution Times With {compiler_name}")
ax.set_xticks([i + bar_width / 3 for i in index])
ax.set_xticklabels(test_names, rotation=45, ha="right")
ax.legend()
fig.tight_layout()
plt.savefig(output_file)
plt.show()
if __name__ == "__main__":
for compiler_name in ["clang", "gcc"]:
file_prefix = "results" if compiler_name == "clang" else "results_gcc"
for benchmark_name in [
"adobe",
"BenchmarkGame",
"dhrystone",
"polybench",
"stanford",
]:
results1 = load_results(
f"test-suite-build/{file_prefix}_{benchmark_name}.json"
)
results2 = load_results(
f"test-suite-build/{file_prefix}_2_{benchmark_name}.json"
)
results3 = load_results(
f"test-suite-build/{file_prefix}_3_{benchmark_name}.json"
)
(
test_names,
execution_times1,
execution_times2,
execution_times3,
) = compare_results(results1["tests"], results2["tests"], results2["tests"])
plot_comparison(
compiler_name,
benchmark_name,
test_names,
execution_times1,
execution_times2,
execution_times3,
f"same_{compiler_name}_{benchmark_name}_comparison.png",
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment