标题: 批处理中的注释rem 比 :: 效率低 [打印本页]
作者: tireless 时间: 2009-5-1 17:45 标题: 批处理中的注释rem 比 :: 效率低
- COMMAND.COM reads and executes batch files one line at a time; that means that it reads one line, execute it and rereads the file from the beginning to the next line. If you do not have a good disk-cache installed, it is not efficient.
-
- When using REM in your batch files to insert a remark, COMMAND.COM reads the comment line, execute it (i.e., does nothing) and rereads the file from the beginning to the next line.
-
- Furthermore, if you put the REM command on the begin of a line containing a redirection
-
- ex: rem echo something > file.dat
-
- it will not execute the command after the REM, but will redirect nothing to the fileoutput .
-
- To avoid this, there is a trick: use '::' instead of 'REM'. ':' is understood as a label to be used by the 'GOTO' statement (see your DOS documentation); this line will never be executed. As a label cannot begin with a ':', this line will not be considered as an executable line, nor as a label.
-
- ex: replace REM This batch file uses characters like >,...
- by :: This batch file uses characters like >,...
复制代码
http://xset.tripod.com/tip3.htm
作者: tireless 时间: 2009-5-1 17:49
用 timeit 测试 1920 行的 rem 和 ::
Average for _Rem.bat key over 8 runs
Version Number: Windows NT 5.1 (Build 2600)
Exit Time: 8:00 am, Monday, January 1 1601
Elapsed Time: 0:00:01.091
Process Time: 0:00:00.746
System Calls: 75993
Context Switches: 20240
Page Faults: 689
Bytes Read: 14829868
Bytes Written: 35542
Bytes Other: 191620
Average for _WrongLable.bat key over 8 runs
Version Number: Windows NT 5.1 (Build 2600)
Exit Time: 8:00 am, Monday, January 1 1601
Elapsed Time: 0:00:00.423
Process Time: 0:00:00.302
System Calls: 29939
Context Switches: 600
Page Faults: 556
Bytes Read: 14777854
Bytes Written: 11774
Bytes Other: 160889
[ 本帖最后由 tireless 于 2009-5-1 17:53 编辑 ]
作者: 随风 时间: 2009-5-1 18:23
rem 是一个命令,
而 :: 不是命令,应该是不执行的吧。
咦?你说的不是bat ?
作者: tireless 时间: 2009-5-1 18:34 标题: 回复 3楼 的帖子
是 bat。我在两个 bat 中各填入 1920 行的 rem 和 ::。然后用 timeit.exe 测:
for /l %a in (1 1 8) do timeit.exe _Rem.bat
for /l %a in (1 1 8) do timeit.exe _WrongLable.bat
作者: defanive 时间: 2009-5-1 20:58
任何命令的执行都需要时间的:一个是批处理命令重载的时间,一个是命令本身执行需要的时间
作者: augaryliu 时间: 2012-12-7 11:41
我也覺得3樓有道理,我試了也是這樣
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |