You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Here is the prep code. We're going to prep some fake test data instead down below
$DirectoryPath = 'WinNT://Sample-TestPC/Authenticated Users'
# Here we will list the various methods whose performance we want to test:
$Scriptblocks = @(
{
# Here is the prep code we will use to generate fake test data.100k fake servers, and 10k fake serial numbers to lookup.
$n = 100000
Write-Host "Looping $n times..."
$Servers = for ($i = 0; $i -lt $n; $i++) {
$Length = $DirectoryPath.LastIndexOf('/')
$DirectoryPath.Substring(0,$Length)
}
},
{
# Here is the prep code we will use to generate fake test data.100k fake servers, and 10k fake serial numbers to lookup.
$n = 100000
Write-Host "Looping $n times..."
$Servers = for ($i = 0; $i -lt $n; $i++) {
$DirectoryPath | Split-Path -Parent
}
}
)
# Here is our function to test the performance of each method
Function Test-ScriptBlockPerformance {
param (
[Parameter(ValueFromPipeline)]
[scriptblock[]]$ScriptBlock
)
process {
ForEach ($ThisScript in $ScriptBlock) {
Write-Host "Starting test of expression {$ThisScript}"
$Result = Measure-Command -Expression $ThisScript
[pscustomobject]@{
Expression = "{$ThisScript}"
Result = $Result
Ticks = $Result.Ticks
}
}
}
}
# Here is where we invoke our function to run the performance tests, and sort the results to find a winner (the fastest method)
$Leaderboard = $Scriptblocks | Test-ScriptBlockPerformance | Sort-Object -Property Ticks
$Leaderboard | Format-Table Ticks,Expression -AutoSize
Expected Behavior
Code is similar to the second sample code completes in only 3873692 tickets (~69% reduction)
Current Behavior
Export-Permission and dependencies contain code similar to the first sample code which completes in 123239274 ticks
Possible Solution
Replace Split-Path with .Net string manipulation methods
The text was updated successfully, but these errors were encountered:
Expected Behavior
Code is similar to the second sample code completes in only 3873692 tickets (~69% reduction)
Current Behavior
Export-Permission and dependencies contain code similar to the first sample code which completes in 123239274 ticks
Possible Solution
Replace Split-Path with .Net string manipulation methods
The text was updated successfully, but these errors were encountered: