use run_command and loop to measure average execution time
@@ -11,6 +11,7 @@ from pathlib import Path
from typing import Optional, Tuple
from urllib.parse import urlparse
+import numpy as np
import utils # TODO: return back its contents to this file?
import compiler_gym.third_party.llvm as llvm
@@ -167,13 +168,20 @@ class UnrollingCompilationSession(CompilationSession):
],
timeout=30,
)
- # Running 5 times and taking the average
+
+ # TODO: use more accurate methods to measure time
+ # Running 5 times and taking the average of middle 3
+ exec_times = []
+ for _ in range(5):
with Timer() as exec_time:
- os.system(
- f"{self._exe_path}; {self._exe_path}; {self._exe_path}; {self._exe_path}; {self._exe_path}"
+ run_command(
+ [self._exe_path],
+ timeout=30,
)
- exec_time = exec_time.time / 5
- return Observation(scalar_double=exec_time)
+ exec_times.append(exec_time.time)
+ exec_times = np.sort(exec_times)
+ avg_exec_time = np.mean(exec_times[1:4])
+ return Observation(scalar_double=avg_exec_time)
elif observation_space.name == "size":
# compile LLVM to object file
run_command(
