更新时间:2023-11-11 20:07:22
是的.
Measure-Command { .\do_something.ps1 }
请注意,Measure-Command
的一个小缺点是您看不到任何stdout
输出.
Note that one minor downside of Measure-Command
is that you see no stdout
output.
[更新,感谢@JasonMArcher]您可以通过将命令输出传递到写入主机的某些Commandlet中来解决此问题. Out-Default
变为:
[Update, thanks to @JasonMArcher] You can fix that by piping the command output to some commandlet that writes to the host, e.g. Out-Default
so it becomes:
Measure-Command { .\do_something.ps1 | Out-Default }
查看输出的另一种方法是使用.NET Stopwatch
类,如下所示:
Another way to see the output would be to use the .NET Stopwatch
class like this:
$sw = [Diagnostics.Stopwatch]::StartNew()
.\do_something.ps1
$sw.Stop()
$sw.Elapsed