Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Desktop Objects: Process execution timing in batch file http://blog.desktopobjects.net/2011/08/process-execution-timing-in-batch-file.html
:: MODULE ..............: timediff-test.bat
:: AUTHOR ..............: Patryk Szczepankiewicz ( pszczepa [at] gmail [dot] com )
:: REFERENCES ..........: http://blog.desktopobjects.net/2011/08/process-execution-timing-in-batch-file.html
:: USAGE ...............: double-click to demonstrate usage - see code below for more information
::
@echo off
echo.
echo -----
echo FUNCTIONAL TESTS
echo.
echo Compute null difference...
set time1=%time%
echo [NOP]...
set time2=%time%
echo timediff-calc.bat %time1% %time2%
call timediff-calc.bat %time1% %time2%
call:funcExpectVarValv1 _timediff 00:00'00
call:funcExpectVarValv1 _timediff_s 0
call:funcExpectVarValv1 _timediff_fs 00
echo.
echo Compute difference of one second...
set time1=%time%
echo [call sleep.bat 1]...
call sleep.bat 1
set time2=%time%
echo timediff-calc.bat %time1% %time2%
call timediff-calc.bat %time1% %time2%
call:funcExpectVarValv1 _timediff 00:00'01
call:funcExpectVarValv1 _timediff_s 1
call:funcExpectVarValv1 _timediff_fs 01
echo.
echo Use SETLOCAL/ENDLOCAL in order to protect caller's environment variables...
set time1=0:00:01,00
set time2=0:00:02,00
echo timediff-calc.bat %time1% %time2%
@call timediff-calc.bat %time1% %time2%
call:funcExpectVarValv1 time1 "0:00:01,00"
call:funcExpectVarValv1 time2 "0:00:02,00"
echo.
echo -----
echo COMPUTATIONAL TESTS
echo.
echo timediff-calc.bat 0:10:33,23 0:10:33,23
@call timediff-calc.bat 0:10:33,23 0:10:33,23
call:funcExpectVarValv1 _timediff "00:00'00"
echo.
echo timediff-calc.bat 0:10:33,23 0:10:33,24
@call timediff-calc.bat 0:10:33,23 0:10:33,24
call:funcExpectVarValv1 _timediff "00:00'00"
echo.
echo timediff-calc.bat 17:08:26,12 17:10:41,15
@call timediff-calc.bat 17:08:26,12 17:10:41,15
call:funcExpectVarValv1 _timediff "00:02'15"
echo.
echo timediff-calc.bat 08:17:26,12 17:10:41,15
@call timediff-calc.bat 08:17:26,12 17:10:41,15
call:funcExpectVarValv1 _timediff "08:53'15"
echo.
echo timediff-calc.bat 0:12:57.04 0:12:57.04
@call timediff-calc.bat 0:12:57.04 0:12:57.04
call:funcExpectVarValv1 _timediff "00:00'00"
echo.
echo timediff-calc.bat " 0:43:05.92" " 0:43:06.03"
@call timediff-calc.bat " 0:43:05.92" " 0:43:06.03"
call:funcExpectVarValv1 _timediff "00:00'01"
echo.
echo timediff-calc.bat "00:00:00,00" "10:00:00,00"
@call timediff-calc.bat "00:00:00,00" "10:00:00,00"
call:funcExpectVarValv1 _timediff "10:00'00"
set _timediff
echo.
echo timediff-calc.bat "23:59:59,00" "00:00:01,00"
@call timediff-calc.bat "23:59:59,00" "00:00:01,00"
call:funcExpectVarValv1 _timediff "00:00'02"
set _timediff
echo.
echo -----
echo SUMMARY
echo -----
call:funcPrintSummaryv1
echo.
goto:eof
::-------------------------------------------------------------------------------------------------------------------------
::-- Function section starts below here
::-------------------------------------------------------------------------------------------------------------------------
:funcExpectVarValv1
set out_name=%~1
set expected=%~2
call set outputted=%%%out_name%%%
set status=Passed
set explnt=%out_name% --- outputted = '%outputted%' [as expected]
set /a GLOBAL_TOTAL_UNITS_COUNT=%GLOBAL_TOTAL_UNITS_COUNT% + 1
if "%outputted%"=="%expected%" (
set /a GLOBAL_PASSED_UNITS_COUNT=%GLOBAL_PASSED_UNITS_COUNT% + 1
) else (
set GLOBAL_UNIT_TEST_STATUS=Failed
set /a GLOBAL_FAILED_UNITS_COUNT=%GLOBAL_FAILED_UNITS_COUNT% + 1
set status=Failed
set explnt=%out_name% --- outputted = '%outputted%' [whereas expected = '%expected%']
)
set explnt=................................................................................................................................................... %explnt%
echo %status% ....%explnt:~-149%
goto:eof
:funcPrintSummaryv1
if "%GLOBAL_UNIT_TEST_STATUS%"=="" set GLOBAL_UNIT_TEST_STATUS=Passed
if "%GLOBAL_PASSED_UNITS_COUNT%"=="" set GLOBAL_PASSED_UNITS_COUNT=0
if "%GLOBAL_FAILED_UNITS_COUNT%"=="" set GLOBAL_FAILED_UNITS_COUNT=0
if "%GLOBAL_TOTAL_UNITS_COUNT%"=="" set GLOBAL_TOTAL_UNITS_COUNT=0
echo Test Run %GLOBAL_UNIT_TEST_STATUS%.
set GLOBAL_PASSED_UNITS_COUNT= %GLOBAL_PASSED_UNITS_COUNT%
set GLOBAL_FAILED_UNITS_COUNT= %GLOBAL_FAILED_UNITS_COUNT%
set GLOBAL_TOTAL_UNITS_COUNT= %GLOBAL_TOTAL_UNITS_COUNT%
echo. Passed %GLOBAL_PASSED_UNITS_COUNT:~-5%
echo. Failed %GLOBAL_FAILED_UNITS_COUNT:~-5%
echo. ------------
echo. Total %GLOBAL_TOTAL_UNITS_COUNT:~-5%
goto:eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment