有時(shí)候你需要知道命令的執(zhí)行時(shí)間,例如,你可以使用Invoke-WebReques查看網(wǎng)站的響應(yīng),再使用Measure-Command計(jì)算執(zhí)行的時(shí)間。
代碼如下:
$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"
其中返回的時(shí)間間隔屬性中包涵了一個(gè)“TotalMilliseconds”屬性;如果有必須要你也可以使用Round()函數(shù)將其化整,這個(gè)例子中我們將保留小數(shù)點(diǎn)后第一位。
新聞熱點(diǎn)
疑難解答
圖片精選