Recently I have answered another question about performance. A solution found using PowerShell-ISE successfully, and good speed testified using PowerShell Core.
However, running the same script(s) in PowerShell 5.1 displays utterly different results, absolutely worse in the performance improvement. Moreover, the original script runs more than 4× slower than in ISE.
So my question is: where lays a reason for such an enormous variance, and what should I avoid in PowerShell scripting (or, conversely, maybe explicitly load a .NET library or something alike)?
PowerShell-ISE: performance improvement cca 10:1
(good):
.\cr2635wrapper.ps1 -maxLoop 8;$ Host.Name;$ PSVersionTable
VERBOSE: maxRange=7, lowCountThreshold=1, operators="+-*/" permutations=4096 formatString="1{0}2{1}3{2}4{3}5{4}6{5}7" orig. 7 269 756 19,574412 VERBOSE: maxRange=7, lowCountThreshold=1, operators="+-*/" permutations=4096 formatString="1{5}2{4}3{3}4{2}5{1}6{0}7" answer 7 284 839 1,911312 Windows PowerShell ISE Host Name Value ---- ----- PSVersion 5.1.17763.503 PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.17763.503 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1
PowerShell Core: performance improvement cca 28:1
(excellent):
pwsh -noprofile -command .\cr2635wrapper.ps1 -maxLoop 8;$ Host.Name;$ PSVersionTable
VERBOSE: maxRange=7, lowCountThreshold=1, operators="+-*/" permutations=4096 formatString="1{0}2{1}3{2}4{3}5{4}6{5}7" orig. 7 269 756 22,0310531 VERBOSE: maxRange=7, lowCountThreshold=1, operators="+-*/" permutations=4096 formatString="1{5}2{4}3{3}4{2}5{1}6{0}7" answer 7 284 839 0,7800336 ConsoleHost Name Value ---- ----- PSVersion 6.2.0 PSEdition Core GitCommitId 6.2.0 OS Microsoft Windows 10.0.17763 Platform Win32NT PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0
PowerShell 5.1: performance improvement cca 4:3
(very poor):
powershell -noprofile -command .\cr2635wrapper.ps1 -maxLoop 8;$ Host.Name;$ PSVersionTable
VERBOSE: maxRange=7, lowCountThreshold=1, operators="+-*/" permutations=4096 formatString="1{0}2{1}3{2}4{3}5{4}6{5}7" orig. 7 269 756 87,1714765 VERBOSE: maxRange=7, lowCountThreshold=1, operators="+-*/" permutations=4096 formatString="1{5}2{4}3{3}4{2}5{1}6{0}7" answer 7 284 839 64,888286 ConsoleHost Name Value ---- ----- PSVersion 5.1.17763.503 PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.17763.503 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1