文章摘要
这篇文章介绍了在PowerShell中使用`Measure-Command` cmdlet来跟踪命令执行时间的技巧。具体来说,文章通过一个示例展示了如何测量访问指定网站的时间,并使用`Invoke-WebRequest` cmdlet发送HTTP请求。文章提到通过记录命令的执行时间,可以帮助开发者优化脚本性能。此外,文章还提到可以通过将时间值四舍五入到整数毫秒来简化结果的呈现。整体内容简明扼要,重点在于展示如何在PowerShell中实现时间控制和性能优化。
$url=’http://www.powershell.com’
# track execution time:
$timeTaken=Measure-Command -Expression {
$site=Invoke-WebRequest -Uri $url
}
$milliseconds=$timeTaken.TotalMilliseconds
$milliseconds=[Math]::Round($milliseconds, 1)
“This took $milliseconds ms to execute”
© 版权声明
文章版权归作者所有,未经允许请勿转载。



