Thanks everyone, I appreciate the help
This is an experiment to see the differences between native PowerShell CMDLets and DotNET especially when working with large data sets.
The first one I did was read a password list with Get-Content vs [System.IO.File]
PowerShell
Measure-Command -Expression {$PW_PS=Get-Content $Path}
DotNET
Measure-Command -Expression {$Pw_DN=[System.IO.File]::ReadAllLines( ( Resolve-Path $Path ) )}
The second one I did was to sort that list
PowerShell
Measure-Command -Expression {$SortedPw_PS= $Pw_PS | Sort-Object}
DotNET
Measure-Command -Expression {$SortedPw_DN= [array]::sort($Pw_DN)}
The third test was to create an array with 10 million items filled with random numbers between 1 and 10 million. For this one I used three different tests with PowerShell, DotNET and Hybrid.
PowerShell
$items=10000000
Measure-Command -Expression { [Array]$Array1_PS = Get-Random -Count $Items -InputObject (1..$Items)}
DotNET
$Items=10000000
$Random = [System.Random]::new()
Measure-Command -Expression {
[Array]$Array1_DN = ForEach ($Loop in 1..$Items)
{
$Random.Next(1,$Items)
}
}
Hybrid
$Items=10000000
$Array1_HB= New-Object -TypeName System.Collections.ArrayList
Measure-Command -Expression {$Array1_HB.AddRange((Get-Random -Count $Items -InputObject (1..$Items))) }
Here are the results
Time in seconds to read large data file with native Powershell 21.5216665
Time in seconds to read large data file with DotNET 0.0693576
Time in seconds to sort data with native Powershell 18.4273818
Time in seconds to sort data with DotNET 3.0236697
Time in seconds to create an array with 10 million items with native Powershell 21.1890782
Time in seconds to create an array with 10 million items with DotNET 141.3131941
Time in seconds to create an array with 10 million items with Hybrid 30.30894
Total time 236.0904982
Here the time to create an array with 10 million items is the outlier. The results are not what I expected at all. I think the Foreach is causing a major slow down.
These tests were run on a Lenovo T580 i7-8650U with Windows PowerShell
Anyone have have any ideas on how to speed these up? Any feedback would be appreciated!
Thanks again
Tim