I have a problem with performance tuning a code that use SET /A instructions.
I have discoverer that the using the exclamation mark (in certain cases?) is faster than without.
Can any expert explain why this istruction:
Code: Select all
set /a aa=!p[%%i].a!, bb=!p[%%i].b!, cc=!p[%%i].c!
is faster than:
Code: Select all
set /a aa=p[%%i].a, bb=p[%%i].b, cc=p[%%i].c
this is the code that test the time elapsed in centisecond:
Code: Select all
@echo off & setlocal EnableDelayedExpansion
For /L %%i in (1,1,100) do set /a "p[%%i].a=!random! %% 100, p[%%i].b=!random! %% 100, p[%%i].c=!random! %% 100"
set t0=!time!
for /L %%N in (1,1,300) do (
For /L %%i in (1,1,100) do set /a aa=!p[%%i].a!, bb=!p[%%i].b!, cc=!p[%%i].c!
)
set t1=!time!
call :difftime
set t0=!time!
for /L %%N in (1,1,300) do (
For /L %%i in (1,1,100) do set /a aa=p[%%i].a, bb=p[%%i].b, cc=p[%%i].c
)
set t1=!time!
call :difftime
endlocal & goto :eof
:difftime
for /F "tokens=1-8 delims=:.," %%a in ("!t0: =0!:!t1: =0!") do set /a "a=(((1%%e-1%%a)*60)+1%%f-1%%b)*6000+1%%g%%h-1%%c%%d, a+=(a>>31) & 8640000"
echo !a! cs
goto :eof
my results:
Code: Select all
533 cs
829 cs
einstein1969