更新时间:2023-11-23 11:57:28
是的.
Measure-Command { .do_something.ps1 }
请注意,Measure-Command
的一个小缺点是您看不到 stdout
输出.
Note that one minor downside of Measure-Command
is that you see no stdout
output.
[更新,感谢@JasonMArcher] 您可以通过将命令输出通过管道传输到一些写入主机的命令行开关来解决这个问题,例如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