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

[其他] timethis 和 timeit:计算命令的运行时间

[复制链接]
发表于 2011-7-29 11:24:56 | 显示全部楼层 |阅读模式
-----------------------------------
http://bcn.bathome.net/s/tool/index.html?key=timethis
http://www.microsoft.com/download/en/details.aspx?id=3087
-----------------------------------

-----------------------------------
TIMETHIS  :  Command Timing Utility
-----------------------------------

Usage : TIMETHIS "command"

  TimeThis executes the command specified by its arguments, then reports its
  run time in HH:MM:SS.TTT format.  Quotes around the command are required only
  when the command involves redirection via <, >, >>, or |, etc.  Quotes ensure
  that the redirection is applied to the command being timed, rather than the
  TimeThis command itself.

Examples :

  TimeThis DIR C:\WINNT

  TimeThis "DIR C:\WINNT | MORE"


-----------------------------------
http://bcn.bathome.net/s/tool/index.html?key=timeit
http://www.microsoft.com/download/en/details.aspx?id=17657
-----------------------------------

Usage: TIMEIT [-f filename] [-a] [-c] [-i] [-d] [-s] [-t] [-k keyname | -r keyna
me] [-m mask] [commandline...]
where:        -f specifies the name of the database file where TIMEIT
                 keeps a history of previous timings.  Default is .\timeit.dat
              -k specifies the keyname to use for this timing run
              -r specifies the keyname to remove from the database.  If
                 keyname is followed by a comma and a number then it will
                 remove the slowest (positive number) or fastest (negative)
                 times for that keyname.
              -a specifies that timeit should display average of all timings
                 for the specified key.
              -i specifies to ignore non-zero return codes from program
              -d specifies to show detail for average
              -s specifies to suppress system wide counters
              -t specifies to tabular output
              -c specifies to force a resort of the data base
              -m specifies the processor affinity mask
发表于 2011-7-29 11:34:26 | 显示全部楼层
看看,放电中文说明啊?
 楼主| 发表于 2011-7-29 11:45:37 | 显示全部楼层
本帖最后由 tmplinshi 于 2011-7-29 13:04 编辑

timethis 唯一要注意的是,当命令中含有特殊符号时,需要转义,或者在命令的首尾加引号。

示例:


e:\我的文档\桌面>
timethis sren -n "s/p/[p]/g" *.pl

TimeThis :  Command Line :  sren -n s/p/[p]/g *.pl
TimeThis :    Start Time :  Fri Jul 29 11:05:41 2011

"r.pl" -> "r.[p]l"
"pren.pl" -> "[p]ren.[p]l"
"rrr.pl" -> "rrr.[p]l"

TimeThis :  Command Line :  sren -n s/p/[p]/g *.pl
TimeThis :    Start Time :  Fri Jul 29 11:05:41 2011
TimeThis :      End Time :  Fri Jul 29 11:05:41 2011
TimeThis :  Elapsed Time :  00:00:00.312

e:\我的文档\桌面>
timethis "dir /b *.pl | pren -n s/p/[p]/g"

TimeThis :  Command Line :  dir /b *.pl | pren -n s/p/[p]/g
TimeThis :    Start Time :  Fri Jul 29 11:06:13 2011

reading filenames from STDIN
r.pl renamed as r.[p]l
pren.pl renamed as [p]ren.[p]l
rrr.pl renamed as rrr.[p]l

TimeThis :  Command Line :  dir /b *.pl | pren -n s/p/[p]/g
TimeThis :    Start Time :  Fri Jul 29 11:06:13 2011
TimeThis :      End Time :  Fri Jul 29 11:06:14 2011
TimeThis :  Elapsed Time :  00:00:00.500
 楼主| 发表于 2011-7-29 13:04:28 | 显示全部楼层
本帖最后由 tmplinshi 于 2011-7-29 14:47 编辑

timeit 不能直接计算 cmd 的内部命令,但可以用以下方法:
  • timeit cmd /c 内部命令
  • 将内部命令保存到文件中,例如命名为 test.bat,然后 timeit test.bat


先贴一个示例:

e:\我的文档\桌面>timeit cmd /c "dir /b *.pl | pren.exe -n s/p/[p]/g"
reading filenames from STDIN
r.pl renamed as r.[p]l
pren.pl renamed as [p]ren.[p]l
rrr.pl renamed as rrr.[p]l

Version Number:   Windows NT 5.1 (Build 2600)
Exit Time:        11:57 am, Friday, July 29 2011
Elapsed Time:     0:00:00.375
Process Time:     0:00:00.062
System Calls:     7225
Context Switches: 626
Page Faults:      2659
Bytes Read:       187558
Bytes Written:    23
Bytes Other:      8114

e:\我的文档\桌面>
timeit cmd /c sren.bat -n s/p/[p]/g *.pl
"r.pl" -> "r.[p]l"
"pren.pl" -> "[p]ren.[p]l"
"rrr.pl" -> "rrr.[p]l"

Version Number:   Windows NT 5.1 (Build 2600)
Exit Time:        11:57 am, Friday, July 29 2011
Elapsed Time:     0:00:00.281
Process Time:     0:00:00.046
System Calls:     9698
Context Switches: 747
Page Faults:      2742
Bytes Read:       186954
Bytes Written:    71
Bytes Other:      12572


(注: timeit cmd /c sren.bat -n s/p/[p]/g *.pl 是可以直接写成 timeit sren.bat -n s/p/[p]/g *.pl 的,这里是为了跟 pren.exe 做对比而使用相同的测试环境。)

  • 可以看到的是 timeit 比较专业,除了计算了运行时间,还有其他的信息。
  • 另一个较好的功能是,计算同一个程序多次后,可以得出平均值。


8 次的平均值:

e:\我的文档\桌面\test>timeit
Average for sren 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.289
Process Time:     0:00:00.089
System Calls:     10490
Context Switches: 1053
Page Faults:      2732
Bytes Read:       73880
Bytes Written:    602
Bytes Other:      15897


-f 指定 timeit 的数据记录文件。默认保存在 .\timeit.dat。

-k 指定所运行的程序保存在 timeit.dat 中的名称。
例如:
  • timeit cmd /c "dir /b *.pl | pren -n s/p/[p]/g"     记录在 timeit.dat 中的名称是 cmd
  • timeit cmd /c sren -n s/p/[p]/g *.pl                  记录的名称也是 cmd

指定名称就能区分了:
  • timeit -k pren cmd /c "dir /b *.pl | pren -n s/p/[p]/g"
  • timeit -k sren cmd /c sren -n s/p/[p]/g *.pl


-r 删除指定的记录名称。
可在名称后跟“逗号数字”。例如:
  • timeit -r sren,1         删除第一次记录
  • timeit -r sren,-2        删除最后两次记录

-d 详细输出

-s 只计算运行时间,不统计其他信息

-t tab 输出
e:\我的文档\桌面\test>timeit -t
Runs Name                      Elapsed Time   Process Time    System   Context    Page    Total I/O
                                                                                      Calls  Switches   Faults
8       pren                        0:00:00.388   0:00:00.085     8145         632      2768     198327
8       sren                        0:00:00.281   0:00:00.091     10573       894      2860      90262
发表于 2011-7-29 14:16:26 | 显示全部楼层
谢谢,有空好好研究下!~
发表于 2011-7-29 15:20:14 | 显示全部楼层
楼主,下载地址呢?
上传上来吧!
 楼主| 发表于 2011-7-29 15:59:13 | 显示全部楼层
回复 6# 2010sftv


    已上传。
发表于 2011-7-31 12:33:11 | 显示全部楼层
版主你是在哪里收集这些外部命令的?
 楼主| 发表于 2011-7-31 13:19:19 | 显示全部楼层
本帖最后由 tmplinshi 于 2011-7-31 13:22 编辑

回复 8# Hello123World


呵呵,曾经疯狂的...
  • 在 Google 里搜索:
    • command line tool
    • command line utility
    • "command line utilities"
    • console tool win32
    • command line .exe
    • ...
  • 在下载站里搜索 command line
  • ...
发表于 2011-7-31 13:28:57 | 显示全部楼层
回复 9# tmplinshi
犀利。——我对你的敬仰犹如滔滔江水……,又如黄河泛滥……
这贴是授人以渔了。
发表于 2011-7-31 13:58:38 | 显示全部楼层
回复 10# Hello123World


必须的嘛,要不然怎么人家是版主咱不是呢
发表于 2011-7-31 20:09:25 | 显示全部楼层
感觉介个工具用处不是很大啊。对于一般用户来说。
发表于 2013-7-30 19:25:19 | 显示全部楼层
求分享 sren 和 pren...大大的好料
 楼主| 发表于 2013-7-31 00:05:07 | 显示全部楼层
本帖最后由 tmplinshi 于 2013-7-31 00:08 编辑
求分享 sren 和 pren...大大的好料
CrLf 发表于 2013-7-30 19:25



pren.exe 是用 perl 脚本转的。帖子地址: http://bathome.net/thread-13342-1-1.html
sren.bat 是结合了 sed 来重命名。不过代码丢失了。

我现在用的是 ren2 (http://www.lomont.org/Software/Utilities/Ren2/ren2.exe)
发表于 2013-7-31 00:46:35 | 显示全部楼层
回复 14# tmplinshi


    记得以前哪个帖子说 ren2 存在重复命名的问题,sren 应该免疫,pren 不知道会不会有这现象
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-17 07:31 , Processed in 0.024395 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

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