Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Created August 17, 2019 17:31
Show Gist options
  • Save guitarrapc/07809ddbefadbbb266570bddaa291d56 to your computer and use it in GitHub Desktop.
Save guitarrapc/07809ddbefadbbb266570bddaa291d56 to your computer and use it in GitHub Desktop.
Odd calc with Class / Static
class Calc {
static [bool] IsOddStatic([int]$value) {
return $value % 2 -eq 0
}
[bool] IsOdd([int]$value) {
return $value % 2 -eq 0
}
}
benchmark -Sb { (1..100).Where{ [Calc]::IsOddStatic($_) } | Measure -Sum } -Repeat 1000 -Way static
$calc = [Calc]::new()
benchmark -Sb { (1..100).Where{ $calc.IsOdd($_) } | Measure -Sum } -Repeat 1000 -Way class
@guitarrapc
Copy link
Author

guitarrapc commented Aug 17, 2019

Benchmark(Method) Times Avg(ms)
shift 1000 1.287
class 1000 1.088

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment