File tree 2 files changed +16
-8
lines changed
2 files changed +16
-8
lines changed Original file line number Diff line number Diff line change 1
1
import json
2
+ import re
2
3
import time
3
4
from dataclasses import dataclass
4
5
@@ -48,12 +49,18 @@ def __run_day(self, day: Day) -> list[RuntimeInfo]:
48
49
49
50
def __run_language (self , language : Language , day : Day ) -> RuntimeInfo :
50
51
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 )
55
55
return RuntimeInfo (day , language .name , runtime )
56
56
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
+
57
64
def __save (self , name : str , runtimes : list [RuntimeInfo ]) -> None :
58
65
if not self .save :
59
66
return
Original file line number Diff line number Diff line change 1
1
import subprocess
2
2
3
3
4
- def execute (command : list [str ]) -> None :
4
+ def execute (command : list [str ]) -> str :
5
5
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 )
8
8
if result .returncode != 0 :
9
9
error_message = result .stderr .decode ()
10
10
print (error_message )
11
11
exit (1 )
12
- return None
12
+ else :
13
+ return result .stdout .decode ()
You can’t perform that action at this time.
0 commit comments