我正在编写一个对可执行文件执行某些优化的程序,并正在寻找一种方法来测量可执行文件运行的时间。
我一直在使用一个测量开始时间和结束时间的脚本,但这并没有考虑到该过程可能不会一直运行(由于操作系统资源分配)。
PowerShell 命令“Measure-Command”会给我更精确的响应吗?“Time”在 Linux 上会做同样的事情吗?
如果没有,我该怎么做?(最好使用命令行解决方案。)
答案1
我不能说 Windows 命令,但是是的,*nix时间将给你更精确的答复:
$ time du -sch /usr/local/
147M /usr/local/
147M total
real 0m2.977s
user 0m0.008s
sys 0m0.076s
据man time
它可以显示(其中许多其他事情):
E Elapsed real (wall clock) time used by
the process, in
[hours:]minutes:seconds.
P Percentage of the CPU that this job
got. This is just user + system times
divided by the total running time. It
also prints a percentage sign.
S Total number of CPU-seconds used by the
system on behalf of the process (in
kernel mode), in seconds.
U Total number of CPU-seconds that the
process used directly (in user mode),
in seconds.
e Elapsed real (wall clock) time used by
the process, in seconds.
答案2
在 PowerShell 中,您可以使用 Get-Process:
Get-Process | select starttime