From cb6d8ced33dd72365d2a2dc0c0820d38af296be8 Mon Sep 17 00:00:00 2001 From: Daneck1988 Date: Tue, 15 Oct 2024 12:29:31 -0300 Subject: [PATCH] Batch now displays call execution time --- run.bat | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/run.bat b/run.bat index 1d9d579..c3c3289 100644 --- a/run.bat +++ b/run.bat @@ -25,7 +25,12 @@ for %%g in (%TEST_FOLDER%\*) do ( for /f "delims=" %%h in ("!testname!") do set optimal=!solutions[%%h]! echo Arquivo de teste: %%g + + set start_t=!TIME! for /f "tokens=4" %%h in ('!EXEC! !ARGS! ^< %%g') do set res=%%h + set end_t=!TIME! + call :difftime !start_t! !end_t! difference + echo Resultado do programa: !res! if defined optimal ( echo Resultado ótimo: !optimal! @@ -36,6 +41,7 @@ for %%g in (%TEST_FOLDER%\*) do ( echo Diferença de !diff! ) ) + echo Tempo de execução: !difference! segundos ) endlocal @@ -43,4 +49,30 @@ set EXEC= set TEST_FOLDER= set SOLUTIONS_FILE= set ARGS= +goto :eof + +rem Function that gets the difference between two %TIME% variables, expects args= start(VAL), end(VAL), ret(VARNAME) +rem This function assumes that the difference in time is LESS THAN 24 HOURS; If the difference is larger, return is incorrect +:difftime +setlocal + + for /f "tokens=1-3 delims=:" %%a in ("%~1") do ( + set /a start_h= ^(1%%a-100^) * 3600 + set /a start_m= ^(1%%b-100^) * 60 + set /a start_s= ^(1%%c-100^) + ) + + for /f "tokens=1-3 delims=:" %%a in ("%~3") do ( + set /a end_h= ^(1%%a-100^) * 3600 + set /a end_m= ^(1%%b-100^) * 60 + set /a end_s= ^(1%%c-100^) + ) + + set /a start_i= %start_h% + %start_m% + %start_s% + set /a end_i= %end_h% + %end_m% + %end_s% + set /a diff_t= %end_i% - %start_i% + + if diff_t LSS 0 set /a diff_t= %diff_t%+86400 + +endlocal & set %~5=%diff_t% goto :eof \ No newline at end of file