diff --git a/PSOneTools/2.4/Foreach-ObjectFast.ps1 b/PSOneTools/2.4/Invoke-PSOneForeach.ps1 similarity index 65% rename from PSOneTools/2.4/Foreach-ObjectFast.ps1 rename to PSOneTools/2.4/Invoke-PSOneForeach.ps1 index 757c996..80fe4f6 100644 --- a/PSOneTools/2.4/Foreach-ObjectFast.ps1 +++ b/PSOneTools/2.4/Invoke-PSOneForeach.ps1 @@ -1,37 +1,37 @@ -function Foreach-ObjectFast +function Invoke-PSOneForeach { <# .SYNOPSIS - Faster Foreach-Object + Faster ForEach-Object .DESCRIPTION - Foreach-ObjectFast can replace the built-in Foreach-Object and improves pipeline speed considerably. - Foreach-ObjectFast supports only the most commonly used parameters -Begin, -Process, and -End, so you can replace + Invoke-PSOneForeach can replace the built-in ForEach-Object and improves pipeline speed considerably. + Invoke-PSOneForeach supports only the most commonly used parameters -Begin, -Process, and -End, so you can replace - 1..100 | Foreach-Object { 'Server{0:d3}' -f $_ } + 1..100 | ForEach-Object { 'Server{0:d3}' -f $_ } with - 1..100 | Foreach-ObjectFast { 'Server{0:d3}' -f $_ } + 1..100 | Invoke-PSOneForeach { 'Server{0:d3}' -f $_ } - but you cannot currently replace instances of Foreach-Object that uses the less commonly used parameters, + but you cannot currently replace instances of ForEach-Object that uses the less commonly used parameters, like -RemainingScripts, -MemberNames, and -ArgumentList - Foreach-ObjectFast has a performance benefit per iteration, so the more objects + Invoke-PSOneForeach has a performance benefit per iteration, so the more objects you send through the pipeline, the more significant performace benefits you will see. - Foreach-ObjectFast is using a steppable pipeline internally which performs better. + Invoke-PSOneForeach is using a steppable pipeline internally which performs better. However because of this, the debugging experience will be different, and internal variables such as $MyInvocation may yield different results. For most every-day tasks, these changes are not important. - A complete explanation of what Where-ObjectFast does can be found here: + A complete explanation of what Invoke-PSOneWhere does can be found here: https://powershell.one/tricks/performance/pipeline .EXAMPLE $stopwatch = [System.Diagnostics.Stopwatch]::StartNew() - $result = 1..1000000 | Foreach-ObjectFast -Process { + $result = 1..1000000 | Invoke-PSOneForeach -Process { "I am at $_" } @@ -39,14 +39,17 @@ $report -f $result.Count, $stopwatch.Elapsed.TotalSeconds Demos the speed improvements. Run this script to see how well it performs, - then replace Foreach-ObjectFast with the default Foreach-Object, and check out + then replace Invoke-PSOneForeach with the default ForEach-Object, and check out the performace difference. $result is the same in both cases. .LINK https://powershell.one/tricks/performance/pipeline - https://github.com/TobiasPSP/Modules.PSOneTools/blob/master/PSOneTools/1.2/Foreach-ObjectFast.ps1 + https://github.com/TobiasPSP/Modules.PSOneTools/blob/master/PSOneTools/1.2/Invoke-PSOneForeach.ps1 #> - + + # creates command shortcuts for the function + [Alias('ForEach-ObjectFast','ForEachObj')] + param ( # executes for each pipeline element diff --git a/PSOneTools/2.4/Group-ObjectFast.ps1 b/PSOneTools/2.4/Invoke-PSOneGroup.ps1 similarity index 94% rename from PSOneTools/2.4/Group-ObjectFast.ps1 rename to PSOneTools/2.4/Invoke-PSOneGroup.ps1 index b0ea530..ef481c8 100644 --- a/PSOneTools/2.4/Group-ObjectFast.ps1 +++ b/PSOneTools/2.4/Invoke-PSOneGroup.ps1 @@ -1,7 +1,8 @@ - - -function Group-ObjectFast +function Invoke-PSOneGroup { + # creates command shortcuts for the function + [Alias('Group-ObjectFast','GroupObj')] + [CmdletBinding(DefaultParameterSetName='Analysis')] param ( diff --git a/PSOneTools/2.4/Where-ObjectFast.ps1 b/PSOneTools/2.4/Invoke-PSOneWhere.ps1 similarity index 70% rename from PSOneTools/2.4/Where-ObjectFast.ps1 rename to PSOneTools/2.4/Invoke-PSOneWhere.ps1 index d8db361..617020d 100644 --- a/PSOneTools/2.4/Where-ObjectFast.ps1 +++ b/PSOneTools/2.4/Invoke-PSOneWhere.ps1 @@ -1,38 +1,38 @@ -function Where-ObjectFast +function Invoke-PSOneWhere { <# .SYNOPSIS Faster Where-Object .DESCRIPTION - Where-ObjectFast can replace the built-in Where-Object and improves pipeline speed considerably. - Where-ObjectFast supports only the scriptblock version of Where-Object, so you can replace + Invoke-PSOneWhere can replace the built-in Where-Object and improves pipeline speed considerably. + Invoke-PSOneWhere supports only the scriptblock version of Where-Object, so you can replace Get-Service | Where-Object { $_.Status -eq 'Running' } with - Get-Service | Where-ObjectFast { $_.Status -eq 'Running' } + Get-Service | Invoke-PSOneWhere { $_.Status -eq 'Running' } but you cannot currently replace the short form of Where-Object: Get-Service | Where-Object Status -eq Running - Where-ObjectFast has a performance benefit per iteration, so the more objects + Invoke-PSOneWhere has a performance benefit per iteration, so the more objects you send through the pipeline, the more significant performace benefits you will see. - Where-ObjectFast is using a steppable pipeline internally which performs better. + Invoke-PSOneWhere is using a steppable pipeline internally which performs better. However because of this, the debugging experience will be different, and internal variables such as $MyInvocation may yield different results. For most every-day tasks, these changes are not important. - A complete explanation of what Where-ObjectFast does can be found here: + A complete explanation of what Invoke-PSOneWhere does can be found here: https://powershell.one/tricks/performance/pipeline .EXAMPLE $stopwatch = [System.Diagnostics.Stopwatch]::StartNew() - $result = 1..1000000 | Where-ObjectFast -FilterScript { + $result = 1..1000000 | Invoke-PSOneWhere -FilterScript { $_ % 5 } @@ -40,14 +40,16 @@ $report -f $result.Count, $stopwatch.Elapsed.TotalSeconds Demos the speed improvements. Run this script to see how well it performs, - then replace Where-ObjectFast with the default Where-Object, and check out + then replace Invoke-PSOneWhere with the default Where-Object, and check out the performace difference. $result is the same in both cases. .LINK https://powershell.one/tricks/performance/pipeline - https://github.com/TobiasPSP/Modules.PSOneTools/blob/master/PSOneTools/1.2/Where-ObjectFast.ps1 + https://github.com/TobiasPSP/Modules.PSOneTools/blob/master/PSOneTools/1.2/Invoke-PSOneWhere.ps1 #> + # creates command shortcuts for the function + [Alias('Where-ObjectFast','WhereObj')] param ( diff --git a/PSOneTools/2.4/PSOneTools.psd1 b/PSOneTools/2.4/PSOneTools.psd1 index b6ae825..0b74beb 100644 Binary files a/PSOneTools/2.4/PSOneTools.psd1 and b/PSOneTools/2.4/PSOneTools.psd1 differ diff --git a/PSOneTools/2.4/module.psm1 b/PSOneTools/2.4/module.psm1 index 220c8c5..ab0847b 100644 --- a/PSOneTools/2.4/module.psm1 +++ b/PSOneTools/2.4/module.psm1 @@ -11,13 +11,13 @@ . $PSScriptRoot\Assert-PSOneFolderExists.ps1 . $PSScriptRoot\Test-PSOnePort.ps1 . $PSScriptRoot\Test-PSOnePing.ps1 -. $PSScriptRoot\Foreach-ObjectFast.ps1 -. $PSScriptRoot\Where-ObjectFast.ps1 +. $PSScriptRoot\Invoke-PSOneForeach.ps1 +. $PSScriptRoot\Invoke-PSOneWhere.ps1 . $PSScriptRoot\Test-PSOneScript.ps1 . $PSScriptRoot\Get-PSOneToken.ps1 . $PSScriptRoot\Expand-PSOneToken.ps1 . $PSScriptRoot\Get-PSOneDirectory.ps1 -. $PSScriptRoot\Group-ObjectFast.ps1 +. $PSScriptRoot\Invoke-PSOneGroup.ps1 . $PSScriptRoot\Find-PSOneDuplicateFile.ps1 . $PSScriptRoot\Show-PSOneApplicationWindow.ps1 . $PSScriptRoot\Get-PSOneClipboardListenerStatus.ps1