找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 18790|回复: 5

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

[复制链接]
发表于 2009-5-1 17:45:47 | 显示全部楼层 |阅读模式
  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
 楼主| 发表于 2009-5-1 17:49:27 | 显示全部楼层
用 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:04 | 显示全部楼层
rem 是一个命令,
而 :: 不是命令,应该是不执行的吧。
咦?你说的不是bat ?
 楼主| 发表于 2009-5-1 18:34:44 | 显示全部楼层

回复 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
发表于 2009-5-1 20:58:29 | 显示全部楼层
任何命令的执行都需要时间的:一个是批处理命令重载的时间,一个是命令本身执行需要的时间
发表于 2012-12-7 11:41:13 | 显示全部楼层
我也覺得3樓有道理,我試了也是這樣
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 01:06 , Processed in 0.018208 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表