Advertisement
Gistrec

Get command execution time

Sep 23rd, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.11 KB | None | 0 0
  1. :: Скрипт нужен для измерения времени выполнения программы
  2. :: Пример вывода "Command took 0:0:13.97 (13.97s total)"
  3.  
  4. @echo off
  5. @setlocal
  6.  
  7. set start=%time%
  8.  
  9. :: Runs your command
  10. cmd /c %*
  11.  
  12. set end=%time%
  13. set options="tokens=1-4 delims=:.,"
  14. for /f %options% %%a in ("%start%") do set start_h=%%a&set /a start_m=100%%b %% 100&set /a start_s=100%%c %% 100&set /a start_ms=100%%d %% 100
  15. for /f %options% %%a in ("%end%") do set end_h=%%a&set /a end_m=100%%b %% 100&set /a end_s=100%%c %% 100&set /a end_ms=100%%d %% 100
  16.  
  17. set /a hours=%end_h%-%start_h%
  18. set /a mins=%end_m%-%start_m%
  19. set /a secs=%end_s%-%start_s%
  20. set /a ms=%end_ms%-%start_ms%
  21. if %ms% lss 0 set /a secs = %secs% - 1 & set /a ms = 100%ms%
  22. if %secs% lss 0 set /a mins = %mins% - 1 & set /a secs = 60%secs%
  23. if %mins% lss 0 set /a hours = %hours% - 1 & set /a mins = 60%mins%
  24. if %hours% lss 0 set /a hours = 24%hours%
  25. if 1%ms% lss 100 set ms=0%ms%
  26.  
  27. :: Mission accomplished
  28. set /a totalsecs = %hours%*3600 + %mins%*60 + %secs%
  29. echo Command took %hours%:%mins%:%secs%.%ms% (%totalsecs%.%ms%s total)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement