本帖最后由 plp626 于 2011-4-23 09:41 编辑
结论就是: 【结论就是,只看测试代码运行结果,或者直接跳到40楼】
endlocal(不是setlocal)释放掉大量垃圾变量后赋值操作才会变快
代码比较如下:- @echo off
- :: 测试一,垃圾变量在变量空间一内,变量二空间内变量的赋值耗时测试
- setlocal enabledelayedexpansion
- call:tt
- call:etime t1 t2 one
- set one
-
- for /l %%a in (1,1,10000) do set _%%a=1
-
- endlocal&Set one=%one%&setlocal enabledelayedexpansion
- call:tt
- call:etime t1 t2 two
- set two
- set/a pp=two/one
- echo 倍数: !pp!
- pause
-
- :tt -------------------------- sub -----------------------------
- set t1=%time%
- for /l %%a in (1 1 10000)do set/a _9+=2
- set t2=%time%
- goto:eof
- :etime
- set/a %3=1!%2:~-5,2!!%2:~-2!-1!%1:~-5,2!!%1:~-2!,%3+=-6000*("%3>>31")
- goto:eof
复制代码
- @echo off
- :: 测试二,垃圾变量在变量空间二而内,变量空间二内变量的赋值耗时测试。
- setlocal enabledelayedexpansion
- call:tt
- call:etime t1 t2 one
- set one
- endlocal&Set one=%one%&setlocal enabledelayedexpansion
-
- for /l %%a in (1,1,10000) do set _%%a=1
-
- call:tt
- call:etime t1 t2 two
- set two
- set/a pp=two/one
- ECHO 倍数:!pp!
- pause
-
- :tt -------------------------- sub -----------------------------
- set t1=%time%
- for /l %%a in (1 1 10000)do set/a _9+=2
- set t2=%time%
- goto:eof
- :etime
- set/a %3=1!%2:~-5,2!!%2:~-2!-1!%1:~-5,2!!%1:~-2!,%3+=-6000*("%3>>31")
- goto:eof
复制代码
|