Skip to content

Instantly share code, notes, and snippets.

@ebelew
Last active July 8, 2016 02:09
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/22fd89c0d96f38766229faba1689cff6 to your computer and use it in GitHub Desktop.
Save ebelew/22fd89c0d96f38766229faba1689cff6 to your computer and use it in GitHub Desktop.
Time command
###########################################################
# Profiling method
# Usage: TimeThis({ <code> }, "optional name/message for this script block")
#
###########################################################
function TimeThis([scriptblock]$scriptblock, $msg)
{
if (!$stopWatch)
{
$script:stopWatch = new-object System.Diagnostics.StopWatch
}
$stopWatch.Reset()
$stopWatch.Start()
. $scriptblock
$stopWatch.Stop()
if ($msg -eq $null) { $msg = "$scriptblock" }
"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