Skip to content

Commit 6a3a08a

Browse files
Keep track of execution time as well as runtime, get a sense of language / execution overhead
1 parent 83b1771 commit 6a3a08a

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

scripts/command/run.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,30 @@ def execute(self) -> RuntimeInfo:
3434
f" {self.times} times with {self.name}"
3535
)
3636
print(message)
37-
runtimes = [LanguageRunner.run_command(self.command) for _ in range(self.times)]
38-
return RuntimeInfo(self.day, self.name, sum(runtimes) / self.times)
37+
38+
runtimes: list[float] = []
39+
executions: list[float] = []
40+
for _ in range(self.times):
41+
runtime, execution = LanguageRunner.run_command(self.command)
42+
runtimes.append(runtime)
43+
executions.append(execution)
44+
45+
return RuntimeInfo(
46+
day=self.day,
47+
language=self.name,
48+
runtime=sum(runtimes) / self.times,
49+
execution=sum(executions) / self.times,
50+
)
3951

4052
@staticmethod
41-
def run_command(command: list[str]) -> float:
53+
def run_command(command: list[str]) -> tuple[float, float]:
54+
start = time.time_ns()
4255
result = execute(command)
56+
execution_ns = float(time.time_ns() - start)
4357
matches: list[str] = re.findall(r".*Runtime \(ns\): (\d*)", result)
4458
assert len(matches) == 1, "Could not find runtime in output"
4559
runtime_ns = float(matches[0])
46-
return runtime_ns / 1_000_000
60+
return (runtime_ns / 1_000_000, execution_ns / 1_000_000)
4761

4862

4963
@dataclass(frozen=True)

scripts/pojo/runtime_info.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ class RuntimeInfo:
88
day: Day
99
language: str
1010
runtime: float
11+
execution: float
1112

1213
def as_dict(self) -> dict:
13-
return {
14-
"year": int(self.day.year),
15-
"day": int(self.day.day),
16-
"language": self.language,
17-
"runtime": self.runtime,
18-
}
14+
return dict(
15+
year=int(self.day.year),
16+
day=int(self.day.day),
17+
language=self.language,
18+
runtime=self.runtime,
19+
execution=self.execution,
20+
)
1921

2022
@staticmethod
2123
def from_dict(value: dict) -> "RuntimeInfo":
@@ -26,4 +28,5 @@ def from_dict(value: dict) -> "RuntimeInfo":
2628
),
2729
language=value["language"],
2830
runtime=value["runtime"],
31+
execution=value["execution"],
2932
)

0 commit comments

Comments
 (0)