From fec5379d1a7108920eadf72f83395ebf63816277 Mon Sep 17 00:00:00 2001 From: ImportTaste <53661808+ImportTaste@users.noreply.github.com> Date: Fri, 31 Dec 2021 12:22:14 -0600 Subject: [PATCH 1/3] Implement aliases for the 'Fast' functions --- PSOneTools/2.4/Foreach-ObjectFast.ps1 | 5 ++++- PSOneTools/2.4/Group-ObjectFast.ps1 | 7 ++++--- PSOneTools/2.4/Where-ObjectFast.ps1 | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/PSOneTools/2.4/Foreach-ObjectFast.ps1 b/PSOneTools/2.4/Foreach-ObjectFast.ps1 index 757c996..0e541ac 100644 --- a/PSOneTools/2.4/Foreach-ObjectFast.ps1 +++ b/PSOneTools/2.4/Foreach-ObjectFast.ps1 @@ -46,7 +46,10 @@ https://powershell.one/tricks/performance/pipeline https://github.com/TobiasPSP/Modules.PSOneTools/blob/master/PSOneTools/1.2/Foreach-ObjectFast.ps1 #> - + + # creates a command shortcut for the function + [Alias('ForEachObj')] + param ( # executes for each pipeline element diff --git a/PSOneTools/2.4/Group-ObjectFast.ps1 b/PSOneTools/2.4/Group-ObjectFast.ps1 index b0ea530..3bd224f 100644 --- a/PSOneTools/2.4/Group-ObjectFast.ps1 +++ b/PSOneTools/2.4/Group-ObjectFast.ps1 @@ -1,7 +1,8 @@ - - -function Group-ObjectFast +function Group-ObjectFast { + # creates a command shortcut for the function + [Alias('GroupObj')] + [CmdletBinding(DefaultParameterSetName='Analysis')] param ( diff --git a/PSOneTools/2.4/Where-ObjectFast.ps1 b/PSOneTools/2.4/Where-ObjectFast.ps1 index d8db361..3273105 100644 --- a/PSOneTools/2.4/Where-ObjectFast.ps1 +++ b/PSOneTools/2.4/Where-ObjectFast.ps1 @@ -48,6 +48,8 @@ https://github.com/TobiasPSP/Modules.PSOneTools/blob/master/PSOneTools/1.2/Where-ObjectFast.ps1 #> + # creates a command shortcut for the function + [Alias('WhereObj')] param ( From 7f6a1e03826540d79cea23ff933ccd25f81456b8 Mon Sep 17 00:00:00 2001 From: ImportTaste <53661808+ImportTaste@users.noreply.github.com> Date: Fri, 31 Dec 2021 12:49:52 -0600 Subject: [PATCH 2/3] Foreach-ObjectFast -> ForEach-ObjectFast (1/2) --- PSOneTools/2.4/Foreach-ObjectFast.ps1 | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/PSOneTools/2.4/Foreach-ObjectFast.ps1 b/PSOneTools/2.4/Foreach-ObjectFast.ps1 index 0e541ac..3330fc6 100644 --- a/PSOneTools/2.4/Foreach-ObjectFast.ps1 +++ b/PSOneTools/2.4/Foreach-ObjectFast.ps1 @@ -1,26 +1,26 @@ -function Foreach-ObjectFast +function ForEach-ObjectFast { <# .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 + 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 - 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 | ForEach-ObjectFast { '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 + ForEach-ObjectFast 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. + ForEach-ObjectFast 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. @@ -31,7 +31,7 @@ .EXAMPLE $stopwatch = [System.Diagnostics.Stopwatch]::StartNew() - $result = 1..1000000 | Foreach-ObjectFast -Process { + $result = 1..1000000 | ForEach-ObjectFast -Process { "I am at $_" } @@ -39,12 +39,12 @@ $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 ForEach-ObjectFast 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/ForEach-ObjectFast.ps1 #> # creates a command shortcut for the function From 2ce7444c8a9c37ea85e33c7084c38e807b8f50a3 Mon Sep 17 00:00:00 2001 From: ImportTaste <53661808+ImportTaste@users.noreply.github.com> Date: Fri, 31 Dec 2021 13:11:09 -0600 Subject: [PATCH 3/3] Foreach-ObjectFast -> ForEach-ObjectFast (2/2) --- PSOneTools/2.4/{Foreach-ObjectFast.ps1 => ForEach-ObjectFast.ps1} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename PSOneTools/2.4/{Foreach-ObjectFast.ps1 => ForEach-ObjectFast.ps1} (100%) diff --git a/PSOneTools/2.4/Foreach-ObjectFast.ps1 b/PSOneTools/2.4/ForEach-ObjectFast.ps1 similarity index 100% rename from PSOneTools/2.4/Foreach-ObjectFast.ps1 rename to PSOneTools/2.4/ForEach-ObjectFast.ps1