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

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

是否有内置方式来测量Windows命令行上命令的执行时间?



BIG阳
浏览 2049回答 3
3回答

慕丝7291255

如果使用的是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 maskVersion Number:   Windows NT 5.2 (Build 3790)Exit Time:        7:38 am, Wednesday, April 15 2009Elapsed Time:     0:00:00.000Process Time:     0:00:00.015System Calls:     731Context Switches: 299Page Faults:      515Bytes Read:       0Bytes Written:    0Bytes Other:      298您可以在Windows 2003资源工具包中获取TimeIt。下载这里.

慕妹3146593

或者,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

POPMUISE

如果你想以(hh:mm:ss.ff格式)将执行时间降低到每秒的百分之一秒不需要下载和安装资源包看起来像个大书呆子(谁不喜欢)尝试将以下脚本复制到一个新的批处理文件中(例如,时间蝙蝠):@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小时或更长时间,输出将是错误的。
打开App,查看更多内容
随时随地看视频慕课网APP