[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

批处理中的注释rem 比 :: 效率低

  1. 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.
  2. 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.
  3. Furthermore, if you put the REM command on the begin of a line containing a redirection
  4. ex: rem echo something > file.dat
  5. it will not execute the command after the REM, but will redirect nothing to the fileoutput .
  6. 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.
  7. ex: replace REM This batch file uses characters like >,...
  8. by :: This batch file uses characters like >,...
复制代码
http://xset.tripod.com/tip3.htm

用 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 编辑 ]

TOP

rem 是一个命令,
而 :: 不是命令,应该是不执行的吧。
咦?你说的不是bat ?
技术问题请到论坛发帖求助!

TOP

回复 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

TOP

任何命令的执行都需要时间的:一个是批处理命令重载的时间,一个是命令本身执行需要的时间
第三方命令行工具编程
Http://Hi.Baidu.Com/Console_App

TOP

我也覺得3樓有道理,我試了也是這樣

TOP

返回列表