33import os
44import shutil
55import subprocess
6+ import time
67from pathlib import Path
78
89import typer
910from click ._termui_impl import ProgressBar , V
1011
1112
12- def compile_and_run (file_path : Path , flag : str , progress : ProgressBar [V ]) -> None :
13+ def compile_and_run (file_path : Path , flag : str , progress : ProgressBar [V ], directory : str , timeout : float ) -> None :
1314 output_path = file_path .parent / f"O{ flag } "
1415 shutil .rmtree (output_path , ignore_errors = True )
1516 os .mkdir (output_path )
@@ -19,9 +20,13 @@ def compile_and_run(file_path: Path, flag: str, progress: ProgressBar[V]) -> Non
1920 file .write (result .stderr .decode ())
2021 if result .returncode == 0 :
2122 try :
23+ start_time = time .time ()
2224 run_result = subprocess .run (
23- output_path / "out" , stdout = subprocess .PIPE , stderr = subprocess .PIPE , timeout = 5.0
25+ output_path / "out" , stdout = subprocess .PIPE , stderr = subprocess .PIPE , timeout = timeout
2426 )
27+ end_time = time .time () - start_time
28+ with open (Path (directory ) / "time.log" , "a" ) as file :
29+ file .write (f"{ end_time } \n " )
2530 with open (output_path / "output.log" , "w" ) as file :
2631 file .write (run_result .stdout .decode ())
2732 file .write (run_result .stderr .decode ())
@@ -32,20 +37,21 @@ def compile_and_run(file_path: Path, flag: str, progress: ProgressBar[V]) -> Non
3237 progress .update (1 )
3338
3439
35- def main (threads : int = 4 ) -> None :
36- parser = argparse .ArgumentParser (description = "Process some integers." )
37- parser .add_argument ("directory" , type = str , nargs = "?" , help = "directory of rust files" , default = "outRust" )
38- args = parser .parse_args ()
39- directory = args .directory
40+ def main (threads : int = 8 , timeout : float = 5.0 ) -> None :
41+ directory = "outRust"
4042 files = os .listdir (directory )
41- files .sort ()
43+ files .sort (key = lambda x : int ( x . split ( "file" )[ 1 ]) )
4244 optimization_flags = ["0" , "1" , "2" , "3" , "s" , "z" ]
4345 with typer .progressbar (label = "Progress" , length = len (files ) * len (optimization_flags )) as progress :
4446 with concurrent .futures .ThreadPoolExecutor (max_workers = threads ) as executor :
4547 tasks = []
4648 for file in files :
4749 for flag in optimization_flags :
48- tasks .append (executor .submit (compile_and_run , Path (directory , file , file + ".rs" ), flag , progress ))
50+ tasks .append (
51+ executor .submit (
52+ compile_and_run , Path (directory , file , file + ".rs" ), flag , progress , directory , timeout
53+ )
54+ )
4955 for future in concurrent .futures .as_completed (tasks ):
5056 future .result ()
5157 for file in files :
0 commit comments