Skip to content

Commit 9fc99d9

Browse files
Update run script to pull runtime from output of each solution and fail if runtime cannot be found
1 parent 4e7e46d commit 9fc99d9

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

Diff for: scripts/command/run.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import re
23
import time
34
from dataclasses import dataclass
45

@@ -48,12 +49,18 @@ def __run_day(self, day: Day) -> list[RuntimeInfo]:
4849

4950
def __run_language(self, language: Language, day: Day) -> RuntimeInfo:
5051
print(f"Running year {day.year} day {day.day} with {language.name}")
51-
start = time.time()
52-
execute(language.run_command(day, self.run_args))
53-
runtime = time.time() - start
54-
print(f"Runtime: {runtime:.3f} seconds")
52+
result = execute(language.run_command(day, self.run_args))
53+
print(result)
54+
runtime = Runner.__parse_runtime_seconds(result)
5555
return RuntimeInfo(day, language.name, runtime)
5656

57+
@staticmethod
58+
def __parse_runtime_seconds(result: str) -> float:
59+
matches: list[str] = re.findall(r".*Runtime \(ns\): (\d*)", result)
60+
assert len(matches) == 1, "Could not find runtime in output"
61+
runtime_ns = float(matches[0])
62+
return runtime_ns / 1_000_000_000
63+
5764
def __save(self, name: str, runtimes: list[RuntimeInfo]) -> None:
5865
if not self.save:
5966
return

Diff for: scripts/component/command.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import subprocess
22

33

4-
def execute(command: list[str]) -> None:
4+
def execute(command: list[str]) -> str:
55
if len(command) == 0:
6-
return None
7-
result = subprocess.run(command, stderr=subprocess.PIPE)
6+
return ""
7+
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
88
if result.returncode != 0:
99
error_message = result.stderr.decode()
1010
print(error_message)
1111
exit(1)
12-
return None
12+
else:
13+
return result.stdout.decode()

0 commit comments

Comments
 (0)