Board logo

标题: [其他] timethis 和 timeit:计算命令的运行时间 [打印本页]

作者: tmplinshi    时间: 2011-7-29 11:24     标题: timethis 和 timeit:计算命令的运行时间

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

作者: cjiabing    时间: 2011-7-29 11:34

看看,放电中文说明啊?
作者: tmplinshi    时间: 2011-7-29 11:45

本帖最后由 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

作者: tmplinshi    时间: 2011-7-29 13:04

本帖最后由 tmplinshi 于 2011-7-29 14:47 编辑

timeit 不能直接计算 cmd 的内部命令,但可以用以下方法:


先贴一个示例:

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 做对比而使用相同的测试环境。)



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 中的名称。
例如:

指定名称就能区分了:


-r 删除指定的记录名称。
可在名称后跟“逗号数字”。例如:

-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

作者: cjiabing    时间: 2011-7-29 14:16

谢谢,有空好好研究下!~
作者: 2010sftv    时间: 2011-7-29 15:20

楼主,下载地址呢?
上传上来吧!
作者: tmplinshi    时间: 2011-7-29 15:59

回复 6# 2010sftv


    已上传。
作者: Hello123World    时间: 2011-7-31 12:33

版主你是在哪里收集这些外部命令的?
作者: tmplinshi    时间: 2011-7-31 13:19

本帖最后由 tmplinshi 于 2011-7-31 13:22 编辑

回复 8# Hello123World


呵呵,曾经疯狂的...

作者: Hello123World    时间: 2011-7-31 13:28

回复 9# tmplinshi
犀利。——我对你的敬仰犹如滔滔江水……,又如黄河泛滥……
这贴是授人以渔了。
作者: CUer    时间: 2011-7-31 13:58

回复 10# Hello123World


必须的嘛,要不然怎么人家是版主咱不是呢
作者: BillGates    时间: 2011-7-31 20:09

感觉介个工具用处不是很大啊。对于一般用户来说。
作者: CrLf    时间: 2013-7-30 19:25

求分享 sren 和 pren...大大的好料
作者: tmplinshi    时间: 2013-7-31 00:05

本帖最后由 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)
作者: CrLf    时间: 2013-7-31 00:46

回复 14# tmplinshi


    记得以前哪个帖子说 ren2 存在重复命名的问题,sren 应该免疫,pren 不知道会不会有这现象
作者: 810126769    时间: 2013-8-22 14:26

看来还是任重道远啊!不懂的地方还太多!
作者: roosevelt122007    时间: 2013-10-16 14:48

这个不错~
有空看看~




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2