Created
February 7, 2020 22:04
-
-
Save apankrat/bad696354455028de7c5cc341a9b7d68 to your computer and use it in GitHub Desktop.
To time execution of windows shell commands, e.g. "time-it ping yahoo.com"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
call :reset | |
call :clock | |
%* > nul | |
call :clock | |
call :render | |
exit /B | |
:reset | |
set t0= | |
set t1= | |
exit /B | |
:clock | |
set _time=%time: =% | |
for /F "tokens=1-4 delims=:.," %%a in ("%_time%") do ( | |
set /a a=10000%%a %% 10000 | |
set /a b=10000%%b %% 10000 | |
set /a c=10000%%c %% 10000 | |
set /a d=10000%%d %% 10000 | |
) | |
set /a now="%a% * 360000 + %b% * 6000 + %c% * 100 + %d%" | |
if not defined t0 (set t0=%now%) else (set t1=%now%) | |
exit /B | |
:render | |
set /A cs = "(%t1% - %t0%)" | |
set /A th=(%cs% / 360000) | |
set /A tm=(%cs% - %th%*360000) / 6000 | |
set /A ts=(%cs% - %th%*360000 - %tm%*6000) / 100 | |
set /A tx=(%cs% - %th%*360000 - %tm%*6000 - %ts%*100) * 10 | |
if %th% lss 10 set th=0%th% | |
if %tm% lss 10 set tm=0%tm% | |
if %ts% lss 10 set ts=0%ts% | |
if %tx% lss 10 (set tx=00%th%) else (if %tx% lss 100 (set tx=0%th%)) | |
echo %th%:%tm%:%ts%.%tx% | |
exit /B |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment