Created
March 18, 2023 13:16
-
-
Save kendhia/6d3de5353aa0a6d3bd364d2bb05c6cda to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): | |
test_names = sorted([get_test_name(test) for test in results1]) | |
execution_times1 = [] | |
execution_times2 = [] | |
for (index, value) in enumerate(results1): | |
execution_times1.append(float(results1[index]["metrics"]["exec_time"])) | |
execution_times2.append(float(results2[index]["metrics"]["exec_time"])) | |
return test_names, execution_times1, execution_times2 | |
def plot_comparison(benchmark_name, test_names, execution_times1, execution_times2, 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') | |
ax.set_xlabel('Test Name') | |
ax.set_ylabel('Execution Time') | |
ax.set_title(f'{benchmark_name} Comparison of Execution Times') | |
ax.set_xticks([i + bar_width / 2 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 benchmark_name in ["adobe", "BenchmarkGame", "dhrystone", "polybench", "stanford"]: | |
results1 = load_results(f"test-suite-build/results_{benchmark_name}.json") | |
results2 = load_results(f"test-suite-build/results_gcc_{benchmark_name}.json") | |
test_names, execution_times1, execution_times2 = compare_results(results1["tests"], results2["tests"]) | |
plot_comparison(benchmark_name, test_names, execution_times1, execution_times2, f"{benchmark_name}_comparison.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment