powershell 测量PowerShell命令或PowerShell脚本的速度

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 测量PowerShell命令或PowerShell脚本的速度相关的知识,希望对你有一定的参考价值。

#-----------------------------------------------------
#1 - measure-command way
Measure-Command {Invoke-WebRequest `
    -Uri 'https://gist.githubusercontent.com/techthoughts2/38ccacf3c7d2bf761c3783e131e589df/raw/0a5595f66935e3ebe3f2d69ea7be8b1639357327/profiles' `
    -OutFile C:\rs-pkgs\test\profiles.ps1}
#-----------------------------------------------------
#2 - differencing datetime
$startMs = (Get-Date).Millisecond
Invoke-WebRequest `
    -Uri 'https://gist.githubusercontent.com/techthoughts2/38ccacf3c7d2bf761c3783e131e589df/raw/0a5595f66935e3ebe3f2d69ea7be8b1639357327/profiles' `
    -OutFile C:\rs-pkgs\test\profiles.ps1
$endMS = (Get-Date).Millisecond
$totalTimeTaken = $($endMS - $startMs)
#-----------------------------------------------------
#3 - .net stopwatch class
$stopWatch = [System.Diagnostics.Stopwatch]::StartNew()
Invoke-WebRequest `
    -Uri 'https://gist.githubusercontent.com/techthoughts2/38ccacf3c7d2bf761c3783e131e589df/raw/0a5595f66935e3ebe3f2d69ea7be8b1639357327/profiles' `
    -OutFile C:\rs-pkgs\test\profiles.ps1
$stopWatch.Stop()
$stopWatch.Elapsed.TotalMilliseconds
#-----------------------------------------------------

以上是关于powershell 测量PowerShell命令或PowerShell脚本的速度的主要内容,如果未能解决你的问题,请参考以下文章

如何测量 powershell 脚本中不同功能的持续时间(以秒为单位)?

如何在PowerShell中使用.NET Framework

powershell和powershell ise到底分别干啥用,powershell命令那么长怎么记

powershell怎么运行

如何用C语言执行powershell命令

PowerShell第一讲,别名,变量,命令。