Created
March 7, 2020 15:18
-
-
Save nightroman/ef6c2ce621953422ce38f07d5d9b26e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ForEach-Object -Parallel is not suitable for many input objects with | |
# relatively fast processing. Split-Pipeline is very suitable for this. | |
#requires -version 7.0 | |
$n = $env:NUMBER_OF_PROCESSORS | |
$1 = { | |
$data | Split-Pipeline {process{ }} -Count $n | |
} | |
$2 = { | |
$data | ForEach-Object -Parallel { } -ThrottleLimit $n | |
} | |
$data = 1..10 | |
"1 $((Measure-Command $1).TotalMilliseconds)" | |
"2 $((Measure-Command $2).TotalMilliseconds)" | |
$data = 1..100 | |
"1 $((Measure-Command $1).TotalMilliseconds)" | |
"2 $((Measure-Command $2).TotalMilliseconds)" | |
$data = 1..1000 | |
"1 $((Measure-Command $1).TotalMilliseconds)" | |
"2 $((Measure-Command $2).TotalMilliseconds)" | |
<# | |
1 33.3961 | |
2 82.3118 | |
1 60.6901 | |
2 833.3839 | |
1 56.8623 | |
2 9144.408 | |
#> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment