Skip to content

Instantly share code, notes, and snippets.

@dfinke
Created November 4, 2012 12:59
Show Gist options
  • Save dfinke/4011813 to your computer and use it in GitHub Desktop.
Save dfinke/4011813 to your computer and use it in GitHub Desktop.
Test Timings of multiplication
# Which do you think takes less time to multiply the #'s 1 to 55?
function Test-Timings {
param(
$iterations=5,
$type,
$sb
)
1..$iterations | ForEach {
$TotalMilliseconds = (Measure-Command {& $sb} ).TotalMilliseconds/1000
[pscustomobject]@{
Type = $type
TotalMilliseconds = "{0:N7}" -f $TotalMilliseconds
}
}
}
$(
Test-Timings 5 "IEX Join" { iex (1..55 -join "*") }
Test-Timings 5 "ForEach Pipeline" { 1..55|% {$s=1} {$s*=$_} {$s} }
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment