为了账号安全,请及时绑定邮箱和手机立即绑定

如何测量Windows命令行上命令的执行时间?

如何测量Windows命令行上命令的执行时间?

BIG阳 2019-07-04 12:32:23
如何测量Windows命令行上命令的执行时间?是否有内置方式来测量Windows命令行上命令的执行时间?
查看完整描述

3 回答

?
慕丝7291255

TA贡献1859条经验 获得超6个赞

如果使用的是Windows 2003(请注意,Windows Server 2008及更高版本不受支持),则可以使用Windows Server 2003资源工具包,该工具包包含显示详细执行状态的timeit.exe。下面是一个例子,为命令“timeit-?”计时:

C:\>timeit timeit -?

Invalid switch -?

Usage: TIMEIT [-f filename] [-a] [-c] [-i] [-d] [-s] [-t] [-k keyname | -r keyname] [-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


Version Number:   Windows NT 5.2 (Build 3790)

Exit Time:        7:38 am, Wednesday, April 15 2009

Elapsed Time:     0:00:00.000

Process Time:     0:00:00.015

System Calls:     731

Context Switches: 299

Page Faults:      515

Bytes Read:       0

Bytes Written:    0

Bytes Other:      298

您可以在Windows 2003资源工具包中获取TimeIt。下载这里.


查看完整回答
反对 回复 2019-07-04
?
慕妹3146593

TA贡献1820条经验 获得超9个赞

或者,WindowsPowerShell有一个内置命令,类似于Bash的“time”命令。它被称为“测量命令”。您必须确保PowerShell安装在运行它的机器上。

示例输入:

Measure-Command {echo hi}

示例输出:

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 0
Milliseconds      : 0
Ticks             : 1318
TotalDays         : 1.52546296296296E-09
TotalHours        : 3.66111111111111E-08
TotalMinutes      : 2.19666666666667E-06
TotalSeconds      : 0.0001318
TotalMilliseconds : 0.1318


查看完整回答
反对 回复 2019-07-04
?
POPMUISE

TA贡献1765条经验 获得超5个赞

如果你想

  1. 以(hh:mm:ss.ff格式)将执行时间降低到每秒的百分之一秒
  2. 不需要下载和安装资源包
  3. 看起来像个大书呆子(谁不喜欢)

尝试将以下脚本复制到一个新的批处理文件中(例如,时间蝙蝠):

@echo off
@setlocal

set start=%time%

:: Runs your command
cmd /c %*

set end=%time%
set options="tokens=1-4 delims=:.,"
for /f %options% %%a in ("%start%") do set start_h=%%a&set /a start_m=100%%b %% 100&set /a start_s=100%%c %% 100&set /a start_ms=100%%d %% 100
for /f %options% %%a in ("%end%") do set end_h=%%a&set /a end_m=100%%b %% 100&set /a end_s=100%%c %% 100&set /a end_ms=100%%d %% 100

set /a hours=%end_h%-%start_h%
set /a mins=%end_m%-%start_m%
set /a secs=%end_s%-%start_s%
set /a ms=%end_ms%-%start_ms%
if %ms% lss 0 set /a secs = %secs% - 1 & set /a ms = 100%ms%
if %secs% lss 0 set /a mins = %mins% - 1 & set /a secs = 60%secs%
if %mins% lss 0 set /a hours = %hours% - 1 & set /a mins = 60%mins%
if %hours% lss 0 set /a hours = 24%hours%
if 1%ms% lss 100 set ms=0%ms%

:: Mission accomplished
set /a totalsecs = %hours%*3600 + %mins%*60 + %secs%
echo command took %hours%:%mins%:%secs%.%ms% (%totalsecs%.%ms%s total)

使用

如果将timecmd.bat放在路径中的目录中,您可以在以下任何地方调用它:

timecmd [your command]

例如:

C:\>timecmd pause
Press any key to continue . . .
command took 0:0:1.18

如果要执行输出重定向,可以引用如下命令:

timecmd "dir c:\windows /s > nul"

这应该处理从前到午夜后运行的命令,但是如果命令运行了24小时或更长时间,输出将是错误的。


查看完整回答
反对 回复 2019-07-04
  • 3 回答
  • 0 关注
  • 2042 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信