Add benchmarks comparison job
This commit is contained in:
parent
0da7938fef
commit
bf1e3a1b1d
1
.github/workflows/osrm-backend.yml
vendored
1
.github/workflows/osrm-backend.yml
vendored
@ -601,6 +601,7 @@ jobs:
|
|||||||
# - run: echo "CI complete"
|
# - run: echo "CI complete"
|
||||||
|
|
||||||
benchmarks:
|
benchmarks:
|
||||||
|
if: github.event_name == 'pull_request'
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
env:
|
env:
|
||||||
CCOMPILER: clang-13
|
CCOMPILER: clang-13
|
||||||
|
@ -10,8 +10,8 @@ PR_NUMBER = os.getenv('PR_NUMBER')
|
|||||||
REPO_OWNER, REPO_NAME = REPO.split('/')
|
REPO_OWNER, REPO_NAME = REPO.split('/')
|
||||||
|
|
||||||
def create_markdown_table(results):
|
def create_markdown_table(results):
|
||||||
header = "| Benchmark | Master | PR |\n|--------|----|"
|
header = "| Benchmark | Base | PR |\n|--------|----|"
|
||||||
rows = [f"| {result['name']} | {result['master']} | {result['pr']} |" for result in results]
|
rows = [f"| {result['name']} | {result['base']} | {result['pr']} |" for result in results]
|
||||||
return f"{header}\n" + "\n".join(rows)
|
return f"{header}\n" + "\n".join(rows)
|
||||||
|
|
||||||
def get_pr_comments(repo_owner, repo_name, pr_number):
|
def get_pr_comments(repo_owner, repo_name, pr_number):
|
||||||
@ -30,15 +30,15 @@ def update_comment(comment_id, repo_owner, repo_name, body):
|
|||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
|
|
||||||
def collect_benchmark_results(master_folder, pr_folder):
|
def collect_benchmark_results(base_folder, pr_folder):
|
||||||
results = []
|
results = []
|
||||||
results_index = {}
|
results_index = {}
|
||||||
|
|
||||||
for file in os.listdir(master_folder):
|
for file in os.listdir(base_folder):
|
||||||
if not file.endswith('.bench'): continue
|
if not file.endswith('.bench'): continue
|
||||||
with open(f"{master_folder}/{file}") as f:
|
with open(f"{base_folder}/{file}") as f:
|
||||||
result = f.read().strip()
|
result = f.read().strip()
|
||||||
results.append({'master': result, 'pr': None, 'name': os.path.splitext(file)[0]})
|
results.append({'base': result, 'pr': None, 'name': os.path.splitext(file)[0]})
|
||||||
results_index[file] = len(results) - 1
|
results_index[file] = len(results) - 1
|
||||||
|
|
||||||
for file in os.listdir(pr_folder):
|
for file in os.listdir(pr_folder):
|
||||||
@ -48,20 +48,23 @@ def collect_benchmark_results(master_folder, pr_folder):
|
|||||||
if file in results_index:
|
if file in results_index:
|
||||||
results[results_index[file]]['pr'] = result
|
results[results_index[file]]['pr'] = result
|
||||||
else:
|
else:
|
||||||
results.append({'master': None, 'pr': result, 'name': os.path.splitext(file)[0]})
|
results.append({'base': None, 'pr': result, 'name': os.path.splitext(file)[0]})
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if len(sys.argv) != 3:
|
if len(sys.argv) != 3:
|
||||||
print("Usage: python post_benchmark_results.py <master_folder> <pr_folder>")
|
print("Usage: python post_benchmark_results.py <base_folder> <pr_folder>")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
master_folder = sys.argv[1]
|
base_folder = sys.argv[1]
|
||||||
pr_folder = sys.argv[2]
|
pr_folder = sys.argv[2]
|
||||||
|
|
||||||
benchmark_results = collect_benchmark_results(master_folder, pr_folder)
|
benchmark_results = collect_benchmark_results(base_folder, pr_folder)
|
||||||
|
|
||||||
comments = get_pr_comments(REPO_OWNER, REPO_NAME, PR_NUMBER)
|
comments = get_pr_comments(REPO_OWNER, REPO_NAME, PR_NUMBER)
|
||||||
if comments and len(comments) > 0:
|
if not comments or len(comments) > 0:
|
||||||
|
print("No comments found on this PR.")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
first_comment = comments[0]
|
first_comment = comments[0]
|
||||||
markdown_table = create_markdown_table(benchmark_results)
|
markdown_table = create_markdown_table(benchmark_results)
|
||||||
new_benchmark_section = f"<!-- BENCHMARK_RESULTS_START -->\n## Benchmark Results\n{markdown_table}\n<!-- BENCHMARK_RESULTS_END -->"
|
new_benchmark_section = f"<!-- BENCHMARK_RESULTS_START -->\n## Benchmark Results\n{markdown_table}\n<!-- BENCHMARK_RESULTS_END -->"
|
||||||
@ -78,9 +81,8 @@ def main():
|
|||||||
|
|
||||||
update_comment(first_comment['id'], REPO_OWNER, REPO_NAME, updated_body)
|
update_comment(first_comment['id'], REPO_OWNER, REPO_NAME, updated_body)
|
||||||
print("PR comment updated successfully.")
|
print("PR comment updated successfully.")
|
||||||
else:
|
|
||||||
print("No comments found on this PR.")
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
set -e pipefail
|
set -e pipefail
|
||||||
|
|
||||||
function run_benchmarks_for_folder {
|
function run_benchmarks_for_folder {
|
||||||
|
Loading…
Reference in New Issue
Block a user