ex2: benchmark job
This commit is contained in:
@@ -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
24
exercise2/bench.py
Executable 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}")
|
||||
Reference in New Issue
Block a user