add a script to benchmark build times

This commit is contained in:
Bennet Bo Fenner 2024-11-16 13:59:12 +01:00
parent eaf02ef7bd
commit 69da8bdea7

19
script/bench_build.py Normal file
View file

@ -0,0 +1,19 @@
import subprocess
def run_build(crate):
subprocess.run(["touch", f"crates/{crate}/src/{crate}.rs"])
result = subprocess.run(["cargo", "build", "--timings"], capture_output=True, text=True)
output = result.stderr.splitlines()[-1].split(" ")[-1]
return float(output.rstrip('s'))
def run_bench(crate, n = 5):
results = []
for i in range(n):
results.append(run_build(crate))
print(f"Run {i+1}/{n} took {results[-1]} seconds")
average = sum(results) / len(results)
print(f"Average build time: {average:.2f} seconds")
return average
run_bench("project")