虚位以待(AD)
虚位以待(AD)
首页 > 脚本专栏 > Powershell > Powershell检查网站响应并计算执行时间例子

Powershell检查网站响应并计算执行时间例子
类别:Powershell   作者:码皇   来源:互联网   点击:

这篇文章主要介绍了Powershell检查网站响应并计算执行时间例子,本文直接给出实现代码,需要的朋友可以参考下

有时候你需要知道命令的执行时间,例如,你可以使用Invoke-WebReques查看网站的响应,再使用Measure-Command计算执行的时间。

复制代码 代码如下:

$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"

其中返回的时间间隔属性中包涵了一个“TotalMilliseconds”属性;如果有必须要你也可以使用Round()函数将其化整,这个例子中我们将保留小数点后第一位。

相关热词搜索: Powershell 检查网站响应 计算执行时间