Wednesday, September 12, 2012

Timed Commands

 Before Windows Vista and Windows 7called timeit.exe was a great tools to use in performance testing for tools.  I've used it to measure effective transfer rates of command line tools.  In Windows 7, the powershell command measure-command works great in some cases.  I've written this script to aid this time monitoring that should work in all Windows versions.

PoweShell Example output

PS C:\> measure-command { notepad }
Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 0
Milliseconds      : 3
Ticks             : 34410
TotalDays         : 3.98263888888889E-08
TotalHours        : 9.55833333333333E-07
TotalMinutes      : 5.735E-05
TotalSeconds      : 0.003441
TotalMilliseconds : 3.441

DOS Script that will measure how long notepad.exe will run.  Replace the command to fit your needs.

@echo off
set i=0
:start
:: Get the time
FOR /f "tokens=1-4 delims=:. " %%G in ('echo %time%') do call :s_setvar %%G-%%H-%%I-%%J
IF %i% == 0 goto process
IF %i% == 1 goto last
goto last

:s_setvar
SET _mstime=%10
goto :eof

:last
::Arithmetic Operations
SET /a e_h=%_mstime:~0,2% * 3600000
SET /a e_m=%_mstime:~3,2% * 60000
SET /a e_s=%_mstime:~6,2% * 1000
SET /a e_ms=%_mstime:~9,3%
SET /a e_result = %e_h%+%e_m%+%e_s%+%e_ms%-%s_result%

SET /a r_h=%e_result% / 3600000
SET /a r_m=(%e_result% %% 3600000) / 60000
SET /a r_s=((%e_result% %% 3600000 ) %% 60000 ) / 1000
SET /a r_ms=((%e_result% %% 3600000 ) %% 60000 ) %% 1000
ECHO This Process Took: %r_h% Hours %r_m% Minutes %r_s% Seconds %r_ms% milliseconds!!! %e_result%
goto EOF

:process
:: Process the commands and output the start time
set i=1
ECHO Start time is:   [%_mstime%]
SET /a s_h=%_mstime:~0,2% * 3600000
SET /a s_m=%_mstime:~3,2% * 60000
SET /a s_s=%_mstime:~6,2% * 1000
SET /a s_ms=%_mstime:~9,3%
SET /a s_result = %s_h%+%s_m%+%s_s%+%s_ms%
::Commands to run ******************************

notepad

::Command list end *****************************

goto start
:EOF

No comments:

Post a Comment