Skip to content

Instantly share code, notes, and snippets.

@jpoehls
Created March 26, 2012 16:48
Show Gist options
  • Save jpoehls/2206444 to your computer and use it in GitHub Desktop.
Save jpoehls/2206444 to your computer and use it in GitHub Desktop.
PowerShell benchmarking function. Or, the Windows equivalent of Unix's `time` command.
function Measure-ExecutionTime ($cmd) {
<#
.SYNOPSIS
Runs the given script block and returns the execution duration.
Discovered on StackOverflow. http://stackoverflow.com/questions/3513650/timing-a-commands-execution-in-powershell
.EXAMPLE
Measure-ExecutionTime { ping -n 1 google.com }
#>
$sw = [Diagnostics.Stopwatch]::StartNew()
& $cmd
$sw.Stop()
$sw.Elapsed.ToString()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment