Skip to content

Instantly share code, notes, and snippets.

@sergeevabc
Created November 29, 2016 01:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergeevabc/2a33504b881f4f292f94e1579d8f4f2b to your computer and use it in GitHub Desktop.
Save sergeevabc/2a33504b881f4f292f94e1579d8f4f2b to your computer and use it in GitHub Desktop.
Measure execution time
@echo off
:: Get start timestamp
set _time=%time%
set _hours=100%_time:~0,2%%%100
set _min=100%_time:~3,2%%%100
set _sec=100%_time:~6,2%%%100
set _cs=%_time:~9,2%
set /a _started=_hours*60*60*100+_min*60*100+_sec*100+_cs
:: Runs your command
cmd /c %*
:: Get difference in cSeconds
set _time=%time%
set _hours=100%_time:~0,2%%%100
set _min=100%_time:~3,2%%%100
set _sec=100%_time:~6,2%%%100
set _cs=%_time:~9,2%
set /a _duration=_hours*60*60*100+_min*60*100+_sec*100+_cs-_started
:: Populate variables for rendering (100+ needed for padding)
set /a _hours=_duration/60/60/100
set /a _min=100+_duration/60/100%%60
set /a _sec=100+(_duration/100%%60%%60)
set /a _cs=100+_duration%%100
echo.
echo Execution time: %_hours%:%_min:~-2%:%_sec:~-2%.%_cs:~-2%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment