ex2: benchmark job

This commit is contained in:
2025-09-10 17:23:04 +02:00
parent 500560bf31
commit 81ee3fded6
3 changed files with 29 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ SRC := mandel_mpi.c
TARGET := $(SRC:.c=)
ARGS := 1
OUTDIR := out
NBENCH := 1
.PHONY: all clean run
@@ -18,3 +19,6 @@ run: $(TARGET)
clean:
rm -rf $(OUTDIR)
time: $(TARGET)
python3 bench.py '$(OUTDIR)/$(TARGET) 0' $(NBENCH)

24
exercise2/bench.py Executable file
View File

@@ -0,0 +1,24 @@
#!/usr/bin/env python3
from statistics import mean
from subprocess import DEVNULL, run
from sys import argv, exit
from time import perf_counter
def benchmark(cmd, N=10):
times = []
for _ in range(N):
start = perf_counter()
run(cmd, shell=True, stdout=DEVNULL, stderr=DEVNULL)
times.append(perf_counter() - start)
return mean(times)
if __name__ == "__main__":
if len(argv) < 2:
print("usage: python3 bench.py 'cmd' [N]")
exit(1)
cmd = argv[1]
N = int(argv[2]) if len(argv) > 2 else 10
print(f"{benchmark(cmd, N):.4f}")

View File

@@ -26,6 +26,7 @@
gnuplot
ffmpeg
mpi
python3
];
shellHook = ''
echo welcome!