Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner 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
You can’t perform that action at this time.