Last active
July 11, 2016 18:00
-
-
Save ebelew/3fe9e5ebf7ee3e9dc804c47cc9f47467 to your computer and use it in GitHub Desktop.
TimeThis.ps as a script, instead of method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# ########################################################## | |
Profiling method | |
Usage: | |
Measure-Scriptblock { <code> } "optional name/message for this script block" | |
Measure-Scriptblock -Scriptblock { <code> } -$Message "optional name/message for this script block" | |
########################################################## #> | |
param ( | |
[Parameter(Mandatory=$true)] | |
[scriptblock]$Scriptblock, | |
[string]$Message = "$Scriptblock" | |
) | |
Set-StrictMode -version latest | |
$script:StopWatch = new-object System.Diagnostics.StopWatch | |
$stopWatch.Reset() | |
$stopWatch.Start() | |
. $Scriptblock | |
$stopWatch.Stop() | |
Write-Verbose -Verbose "Execution time: $($stopWatch.ElapsedMilliseconds) mS for $msg" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment