Skip to content

Instantly share code, notes, and snippets.

@ebelew
Last active July 11, 2016 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ebelew/3fe9e5ebf7ee3e9dc804c47cc9f47467 to your computer and use it in GitHub Desktop.
Save ebelew/3fe9e5ebf7ee3e9dc804c47cc9f47467 to your computer and use it in GitHub Desktop.
TimeThis.ps as a script, instead of method
<# ##########################################################
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