Advertisement
unknown14725

bench.bat

Aug 13th, 2019
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.68 KB | None | 0 0
  1. @ECHO  off
  2. SETLOCAL ENABLEDELAYEDEXPANSION
  3. CLS
  4.  
  5. :: Small benchmarking script that will tell you how long time it took to call a bat file
  6. :: version 2   - 2016.06.08 - Fixed so leading zeroes don't fuck up. Both SET /A and PERL are dandy now.
  7. :: version 2.1 - 2016.07.27 - Vastly improved SET /A, but a lot more complex. Super fast. Removed perl, because this method is rock steady.
  8.  
  9. SET "argumentsOriginal=%*"
  10. SET "arguments=!argumentsOriginal:%1=!"
  11.  
  12. :: Here we grab start time, execute the script we wanna time, and then grab the end time.
  13. SET "StartTime=%time%"
  14. CALL  %1 %arguments%
  15. SET "EndTime=%time%"
  16.  
  17. :: We add a "1" to M, S, mS so they aren't accidentally read as octals if they show "09".
  18. FOR /F "tokens=1,2,3,4,5,6,7,8 delims=:., " %%A IN ("%StartTime%:%EndTime%") DO ( SET /A "ScriptTimeTaken=(((%%E*60*60*100)+(1%%F*60*100)+(1%%G*100)+1%%H)-((%%A*60*60*100)+(1%%B*60*100)+(1%%C*100)+1%%D))" )
  19. :: If midnight transitions between start and end time, we get a negative number.
  20. IF !ScriptTimeTaken! LSS 0 ( SET /A ScriptTimeTaken=ScriptTimeTaken+8640000 )
  21. :: Depending on number of millisecs, we have to pad output with "0.0" or "0."
  22. IF !ScriptTimeTaken! LEQ 9 ( SET "ExecutionTime=0.0!ScriptTimeTaken:~-2!" ) ELSE ( IF !ScriptTimeTaken! LEQ 99 ( SET "ExecutionTime=0.!ScriptTimeTaken:~-2!" ) ELSE ( IF !ScriptTimeTaken! GEQ 100 ( SET "ExecutionTime=!ScriptTimeTaken:~0,-2!.!ScriptTimeTaken:~-2!" ) ) )
  23.  
  24. ECHO ----------------------------------------------------------------------- 1>&2
  25. ECHO   COMMAND LINE:  !argumentsOriginal! 1>&2
  26. ECHO   ELAPSED TIME:  %ExecutionTime% sec 1>&2
  27. ECHO ----------------------------------------------------------------------- 1>&2
  28.  
  29. :End
  30.  
  31. ECHO.  1>&2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement