techthoughts2
2/11/2018 - 8:20 PM

Measure the speed of a PowerShell Command or PowerShell Script

Three different ways of measuring the speed of a PowerShell command or a PowerShell script

#-----------------------------------------------------
#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
#-----------------------------------------------------