Last active
August 22, 2021 15:39
-
-
Save VertigoRay/3bb0166d6a877839b420 to your computer and use it in GitHub Desktop.
Used Pester to do some speed tests, because the comments on my stackoverflow post (http://stackoverflow.com/a/16175967/615422) peaked my interest.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| Invoked the test with the following command, so that I could save the times take the average of each Context: | |
| ```posh | |
| Invoke-Pester -OutputFile test.xml -OutputFormat NUnitXml | |
| ``` | |
| Then I did some math on the results as shown (yes, I use pipelines when not scripting): | |
| ```posh | |
| [xml]$xml = Get-Content .\test.xml | |
| $times = @( | |
| ($xml.'test-results'.'test-suite'.results.'test-suite'.results.'test-case' | ?{ [int]$_.description -le 1000 } | %{ [decimal]$_.time }), | |
| ($xml.'test-results'.'test-suite'.results.'test-suite'.results.'test-case' | ?{ ([int]$_.description -ge 1001) -and ([int]$_.description -le 2000) } | %{ [decimal]$_.time }), | |
| ($xml.'test-results'.'test-suite'.results.'test-suite'.results.'test-case' | ?{ [int]$_.description -ge 2001 } | %{ [decimal]$_.time }) | |
| ) | |
| # Get Averages | |
| $avgs = $times | %{ $_ | Measure-Object -Average } | |
| Write-Host "Averages: $($avgs | Out-String)" | |
| # Get Medians | |
| $meds = $times | %{ | |
| $data = $_ | sort | |
| if ($data.count%2) { | |
| $MedianValue = $data[[math]::Floor($data.count/2)] | |
| } else { | |
| $MedianValue = ($data[$data.Count/2],$data[$data.count/2-1] |measure -Average).average | |
| } | |
| $MedianValue | |
| } | |
| Write-Host "Medians: $($meds | Out-String)" | |
| #Get Modes | |
| $mods = $times | %{ '---'; ($_ | group | sort -Descending Count)[0..5] } | |
| Write-Host "Modes: $($mods | Out-String)" | |
| ``` | |
| Results are in the comments. | |
| #> | |
| $computerSystem = Get-CimInstance CIM_ComputerSystem | |
| $computerOS = Get-CimInstance CIM_OperatingSystem | |
| $computerCPU = Get-CimInstance CIM_Processor | |
| @" | |
| Manufacturer: {0} | |
| Model: {1} | |
| CPU: {2} | |
| RAM: {3:N2} GB | |
| Operating System: {4} | |
| Service Pack: {5} | |
| PS Version Table: {6} | |
| "@ -f ( | |
| $computerSystem.Manufacturer, | |
| $computerSystem.Model, | |
| $computerCPU.Name, | |
| ($computerSystem.TotalPhysicalMemory/1GB), | |
| $computerOS.caption, | |
| $computerOS.ServicePackMajorVersion, | |
| ($PSVersionTable | Out-String) | |
| ) | |
| Describe 'Looping Speed Test' { | |
| BeforeEach { | |
| $hash = @{ | |
| a = 1 | |
| b = 2 | |
| c = 3 | |
| } | |
| } | |
| Context 'Pipeline Test' { | |
| foreach ($i in 1..500) { | |
| It $i { | |
| { | |
| $hash.Keys | % { "key = $_ , value = " + $hash.Item($_) } | |
| } | Should Not Throw | |
| } | |
| } | |
| } | |
| Context 'ForEach GetEnumerator Test' { | |
| foreach ($i in 1001..1500) { | |
| It $i { | |
| { | |
| foreach ($h in $hash.GetEnumerator()) { | |
| "$($h.Name): $($h.Value)" | |
| } | |
| } | Should Not Throw | |
| } | |
| } | |
| } | |
| Context 'ForEach Keys Test' { | |
| foreach ($i in 2001..2500) { | |
| It $i { | |
| { | |
| foreach ($h in $hash.Keys) { | |
| "${h}: $($hash.Item($h))" | |
| } | |
| } | Should Not Throw | |
| } | |
| } | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's my computer information:
Here's my Averages, Medians, and Modes (calculated as shown above, in the comment block):
Note: The first calculation is the Pipeline Test, then the ForEach GetEnumerator Test, then the ForEach Keys Test.
In case you want my values, here's the result of
$times | ConvertTo-Json -Compress:[{"value":[1.4995,0.0445,0.0484,0.0492,0.0471,0.0493,0.0492,0.0457,0.0504,0.049,0.0559,0.0471,0.0473,0.0432,0.0508,0.0496,0.0446,0.0488,0.0487,0.0498,0.0483,0.0498,0.0482,0.0488,0.0481,0.0482,0.0487,0.0493,0.0464,0.0482,0.0441,0.05,0.0648,0.0519,0.0485,0.0501,0.049,0.0483,0.0442,0.0499,0.0512,0.0492,0.0479,0.0499,0.0481,0.0488,0.0472,0.0486,0.0485,0.0499,0.0493,0.049,0.0505,0.0497,0.0483,0.0503,0.0468,0.0498,0.0493,0.0542,0.045,0.0498,0.0479,0.0472,0.048,0.0484,0.0513,0.0492,0.0496,0.0558,0.0476,0.0487,0.0443,0.0481,0.0481,0.0501,0.0531,0.0491,0.0489,0.0487,0.049,0.0474,0.0493,0.0472,0.0489,0.048,0.0499,0.0485,0.0452,0.0493,0.0487,0.0444,0.0499,0.0472,0.0502,0.0474,0.0525,0.0493,0.0498,0.0512,0.0497,0.0508,0.0487,0.0485,0.0506,0.0496,0.0488,0.0431,0.0483,0.0494,0.0535,0.0497,0.0489,0.0514,0.0506,0.0501,0.0495,0.0497,0.0449,0.0512,0.0492,0.0501,0.0451,0.0482,0.0478,0.0491,0.0493,0.0503,0.053,0.0499,0.0533,0.048,0.0495,0.0492,0.0503,0.0515,0.0456,0.0468,0.0488,0.0484,0.0492,0.0473,0.0486,0.0476,0.0481,0.05,0.0505,0.0497,0.0447,0.0497,0.0499,0.0515,0.0505,0.0501,0.0514,0.0462,0.0498,0.052,0.0497,0.0498,0.0488,0.0478,0.0444,0.0465,0.046,0.0498,0.0492,0.0454,0.0471,0.0516,0.0411,0.0478,0.0507,0.05,0.0455,0.0521,0.0558,0.0488,0.0503,0.0474,0.0455,0.0485,0.0507,0.0536,0.0488,0.0483,0.0453,0.0471,0.0499,0.0487,0.0513,0.0502,0.0499,0.0487,0.0485,0.048,0.0488,0.0489,0.0464,0.0512,0.0615,0.0498,0.04,0.0473,0.0453,0.0461,0.0486,0.0523,0.0459,0.046,0.0499,0.0477,0.0467,0.0502,0.0484,0.0501,0.0521,0.049,0.0503,0.0468,0.0497,0.0489,0.0486,0.0481,0.0459,0.0462,0.0483,0.0495,0.0504,0.0489,0.0502,0.0502,0.0457,0.0497,0.0503,0.0506,0.0475,0.0471,0.0445,0.0485,0.0469,0.049,0.0503,0.0498,0.0505,0.0513,0.0492,0.0498,0.0508,0.0515,0.0499,0.0464,0.0508,0.0511,0.0468,0.0484,0.05,0.0484,0.0494,0.0506,0.0508,0.0504,0.049,0.0496,0.0506,0.05,0.0456,0.0515,0.0492,0.0494,0.0523,0.0491,0.0496,0.0505,0.0522,0.0492,0.0501,0.0488,0.049,0.0497,0.0512,0.0492,0.0433,0.0506,0.0461,0.0499,0.0498,0.0473,0.0453,0.0479,0.0503,0.0498,0.0511,0.0491,0.0456,0.0508,0.0523,0.0438,0.048,0.0524,0.0514,0.0477,0.0492,0.046,0.0482,0.0494,0.0508,0.0478,0.0475,0.0456,0.0477,0.0484,0.0487,0.0526,0.0529,0.0464,0.0464,0.0453,0.0468,0.0556,0.0521,0.0461,0.0483,0.0477,0.0511,0.0462,0.0466,0.0532,0.0468,0.0476,0.0507,0.0464,0.0524,0.0468,0.0508,0.0483,0.046,0.0477,0.0443,0.0498,0.0469,0.0465,0.0517,0.0423,0.0468,0.0446,0.0513,0.0476,0.0436,0.0469,0.0459,0.0455,0.0429,0.0454,0.0464,0.0484,0.0548,0.0598,0.052,0.0434,0.0488,0.0459,0.0493,0.0477,0.0502,0.0453,0.0458,0.0664,0.0612,0.0535,0.0477,0.0478,0.0468,0.0581,0.0522,0.0505,0.0562,0.0463,0.0457,0.0429,0.0518,0.0461,0.0499,0.0463,0.0482,0.0453,0.0473,0.0474,0.0446,0.0446,0.0465,0.0457,0.0452,0.047,0.0502,0.0747,0.0497,0.0505,0.0464,0.0448,0.0436,0.0451,0.0463,0.0442,0.0507,0.0527,0.0559,0.0569,0.0495,0.0427,0.0535,0.0503,0.0485,0.0513,0.0566,0.0503,0.0496,0.0494,0.0494,0.0481,0.0497,0.0479,0.0715,0.0484,0.0501,0.0487,0.0484,0.0465,0.0483,0.053,0.0472,0.0489,0.0505,0.0492,0.0471,0.0531,0.0501,0.0487,0.0472,0.0487,0.0479,0.0501,0.0542,0.044,0.0517,0.0522,0.0461,0.0493,0.0496,0.057,0.0578,0.0481,0.0502,0.0487,0.0469,0.0492,0.0505,0.0479,0.0488,0.0453,0.0481,0.0497,0.0486,0.051,0.0497,0.046,0.049,0.0504,0.0495,0.0507,0.0501,0.0485,0.049,0.0447,0.0482,0.0485,0.0495,0.0669,0.0501,0.0512,0.0488,0.0515,0.0498,0.0483,0.0512,0.0451,0.0516,0.0503,0.0495,0.0493,0.0503,0.0501,0.0505,0.0493,0.0515,0.05,0.0459,0.0536,0.0501,0.0544],"Count":500},{"value":[0.1542,0.0492,0.0597,0.0487,0.0508,0.0549,0.048,0.0445,0.0493,0.0492,0.05,0.0515,0.0502,0.0495,0.052,0.052,0.047,0.0501,0.0497,0.0484,0.0495,0.0464,0.0447,0.0505,0.0498,0.0467,0.0483,0.0519,0.0494,0.0631,0.0478,0.052,0.0531,0.0483,0.0477,0.05,0.0494,0.0486,0.0481,0.0497,0.0516,0.0493,0.0482,0.0494,0.0485,0.0491,0.0416,0.0518,0.048,0.0513,0.0491,0.049,0.0512,0.0492,0.0471,0.0454,0.0492,0.0472,0.0489,0.045,0.0497,0.0457,0.0467,0.0491,0.0494,0.0473,0.0495,0.0493,0.0489,0.0492,0.0458,0.0504,0.0519,0.0511,0.0513,0.0498,0.0498,0.0497,0.047,0.0477,0.0475,0.0453,0.0502,0.0503,0.0442,0.0441,0.0504,0.0501,0.0489,0.0496,0.0483,0.0481,0.0493,0.0488,0.0502,0.0424,0.0511,0.0489,0.0464,0.0501,0.0477,0.0489,0.0501,0.0501,0.049,0.0468,0.0458,0.051,0.0493,0.0478,0.0485,0.0492,0.0457,0.0493,0.0476,0.0496,0.0492,0.0506,0.0494,0.0501,0.0458,0.0503,0.0465,0.0496,0.0483,0.0489,0.0499,0.0495,0.0494,0.051,0.0482,0.0509,0.0443,0.0475,0.0517,0.0481,0.05,0.053,0.049,0.0507,0.0502,0.0492,0.05,0.0499,0.0459,0.0487,0.0496,0.0492,0.0454,0.0504,0.0492,0.049,0.0497,0.0452,0.0495,0.0517,0.0451,0.0514,0.0472,0.0477,0.0506,0.0488,0.0485,0.05,0.0485,0.0519,0.0473,0.0491,0.0483,0.0482,0.0492,0.045,0.0489,0.0491,0.0478,0.046,0.0506,0.0496,0.054,0.0491,0.0505,0.0458,0.0483,0.0492,0.0484,0.0492,0.0482,0.0498,0.0501,0.0485,0.0488,0.0491,0.0497,0.0442,0.0486,0.0501,0.0451,0.0489,0.0497,0.0505,0.0484,0.0487,0.05,0.0452,0.0505,0.0488,0.048,0.0508,0.0495,0.0485,0.0517,0.0492,0.0514,0.051,0.0494,0.0487,0.0415,0.0475,0.048,0.0544,0.0495,0.0483,0.0487,0.0489,0.0489,0.0483,0.0493,0.0446,0.048,0.0481,0.0477,0.0487,0.0475,0.0486,0.0489,0.0509,0.0527,0.044,0.0509,0.0502,0.0493,0.0494,0.0493,0.0498,0.049,0.0524,0.0507,0.0487,0.0479,0.0501,0.0514,0.0494,0.0507,0.0449,0.0495,0.0503,0.0505,0.0497,0.0492,0.0479,0.0506,0.0465,0.049,0.0498,0.0494,0.0493,0.0443,0.0484,0.0515,0.0501,0.0489,0.0489,0.0493,0.0482,0.0481,0.0487,0.048,0.0493,0.0498,0.0447,0.0545,0.0477,0.0471,0.0493,0.0503,0.0518,0.0501,0.0501,0.0509,0.0502,0.0459,0.0488,0.0485,0.0497,0.049,0.0499,0.0498,0.0521,0.0491,0.0491,0.0516,0.0518,0.0454,0.0511,0.0489,0.0502,0.0491,0.0483,0.0498,0.0497,0.0488,0.0486,0.0502,0.0498,0.0503,0.0444,0.0498,0.047,0.0515,0.0504,0.0485,0.0499,0.0498,0.0489,0.0489,0.0499,0.049,0.0487,0.0456,0.0456,0.0464,0.0499,0.0472,0.0453,0.0489,0.0507,0.0499,0.0525,0.0506,0.0482,0.05,0.0577,0.044,0.0502,0.0507,0.0448,0.0502,0.0493,0.0475,0.044,0.0476,0.0502,0.0502,0.0487,0.0459,0.0435,0.0495,0.0437,0.0457,0.0463,0.0465,0.0449,0.0493,0.0528,0.0487,0.0472,0.0491,0.0448,0.0385,0.0458,0.0477,0.0474,0.0472,0.0433,0.0445,0.0474,0.0502,0.0466,0.0511,0.0476,0.0472,0.0408,0.0435,0.0516,0.05,0.0501,0.0498,0.0489,0.0479,0.0485,0.0485,0.0517,0.0511,0.0479,0.049,0.048,0.0451,0.0477,0.0499,0.0498,0.0501,0.0468,0.0496,0.0503,0.0477,0.05,0.0438,0.0513,0.0501,0.0522,0.0468,0.051,0.0498,0.0505,0.0493,0.0499,0.0508,0.0469,0.0509,0.0446,0.049,0.0504,0.0479,0.0488,0.0525,0.0505,0.0489,0.0484,0.0496,0.0502,0.0496,0.0445,0.0505,0.0499,0.0485,0.049,0.0505,0.0496,0.0498,0.0503,0.0456,0.0508,0.0497,0.0457,0.051,0.0484,0.0511,0.049,0.0407,0.0504,0.0499,0.0503,0.0489,0.0496,0.0504,0.05,0.0502,0.0475,0.0459,0.0493,0.0498,0.0497,0.0423,0.0511,0.0506,0.0468,0.0492,0.0491,0.0489,0.0491,0.0505,0.0471,0.0486,0.0491,0.0452,0.0476,0.0498,0.0494,0.0498,0.0499,0.05,0.0518,0.0413,0.0503,0.0488,0.0508,0.0521,0.0482,0.0494,0.0496,0.0498,0.0503,0.0467,0.0447,0.048,0.0504,0.0468,0.0513,0.0505,0.0511],"Count":500},{"value":[0.1793,0.0447,0.0523,0.0551,0.0509,0.0508,0.049,0.0498,0.046,0.0492,0.0438,0.0511,0.0503,0.0514,0.0502,0.0507,0.0498,0.0461,0.0492,0.0503,0.0525,0.0515,0.0509,0.0508,0.0505,0.05,0.0441,0.0471,0.0481,0.051,0.0504,0.0498,0.0592,0.0458,0.0487,0.0508,0.0507,0.0484,0.049,0.0507,0.052,0.0487,0.0498,0.0585,0.0501,0.0493,0.047,0.0441,0.0493,0.0523,0.0471,0.0505,0.0517,0.0509,0.0459,0.0507,0.0514,0.0523,0.0482,0.0515,0.0478,0.0497,0.0505,0.0519,0.0504,0.05,0.0494,0.0502,0.0496,0.0491,0.0497,0.0516,0.0461,0.0499,0.051,0.0497,0.0494,0.0509,0.0504,0.0525,0.0534,0.0506,0.0514,0.0542,0.0504,0.045,0.0493,0.0517,0.0498,0.0495,0.0499,0.0496,0.0493,0.05,0.0543,0.0502,0.0509,0.0414,0.0455,0.0504,0.0509,0.0496,0.0523,0.0507,0.0517,0.0512,0.0505,0.0494,0.0496,0.0509,0.0458,0.0512,0.05,0.0452,0.0508,0.0508,0.0506,0.0498,0.0494,0.0507,0.0526,0.0501,0.0527,0.0497,0.0485,0.0457,0.0498,0.0467,0.0492,0.0495,0.0499,0.0496,0.0503,0.0493,0.0485,0.0416,0.05,0.0471,0.0505,0.0489,0.0496,0.0467,0.0481,0.0472,0.0494,0.0491,0.05,0.0447,0.0508,0.05,0.0499,0.0479,0.0514,0.0494,0.0528,0.0493,0.0514,0.0508,0.0505,0.0456,0.0496,0.0531,0.0502,0.0492,0.0491,0.0473,0.051,0.05,0.0466,0.0501,0.0501,0.0492,0.0453,0.0506,0.0503,0.0526,0.0482,0.048,0.0505,0.0491,0.0499,0.0501,0.0504,0.0502,0.0445,0.0491,0.0498,0.0504,0.0501,0.0499,0.0499,0.0512,0.0508,0.0508,0.0505,0.0498,0.0459,0.0487,0.0514,0.0497,0.0512,0.0516,0.0504,0.054,0.0519,0.0439,0.0477,0.0504,0.0507,0.0479,0.0494,0.0505,0.0507,0.0496,0.0517,0.051,0.0534,0.045,0.0507,0.0501,0.049,0.0519,0.0515,0.0513,0.0535,0.0466,0.0466,0.0478,0.0442,0.0472,0.0502,0.0495,0.0496,0.0487,0.0504,0.0503,0.0502,0.0476,0.049,0.0498,0.0438,0.0507,0.0482,0.0495,0.0502,0.0478,0.0487,0.0488,0.0493,0.0495,0.049,0.0493,0.0476,0.0444,0.0496,0.0514,0.0497,0.0531,0.0482,0.0464,0.052,0.0498,0.0525,0.0502,0.0505,0.0483,0.0441,0.0491,0.0498,0.0501,0.052,0.0505,0.0509,0.0499,0.0508,0.0469,0.0504,0.0505,0.0521,0.0458,0.0505,0.0493,0.0513,0.0464,0.0496,0.0528,0.0524,0.0446,0.0489,0.0502,0.0492,0.0485,0.0509,0.0505,0.0494,0.0493,0.0517,0.0504,0.0498,0.0488,0.0449,0.0499,0.0501,0.0517,0.0517,0.0522,0.0505,0.0511,0.0506,0.0502,0.0494,0.0456,0.049,0.0502,0.0487,0.0499,0.0493,0.0525,0.0474,0.0492,0.0492,0.05,0.0506,0.0499,0.045,0.0492,0.0507,0.0518,0.0497,0.0503,0.0497,0.0509,0.0498,0.0493,0.0485,0.0512,0.0448,0.0505,0.0518,0.0486,0.049,0.051,0.0517,0.052,0.0495,0.0541,0.0518,0.0486,0.0518,0.0494,0.0446,0.0498,0.0494,0.0506,0.049,0.0485,0.0505,0.048,0.0484,0.0472,0.0466,0.0489,0.0445,0.0494,0.0516,0.0513,0.0492,0.0496,0.0496,0.0502,0.0499,0.0506,0.0511,0.0494,0.0502,0.0487,0.0489,0.0457,0.0454,0.0499,0.0467,0.0501,0.051,0.0524,0.0517,0.0508,0.051,0.0495,0.0453,0.0486,0.0515,0.0458,0.0505,0.0503,0.05,0.0502,0.0458,0.051,0.0501,0.0497,0.0513,0.0501,0.0459,0.0488,0.0477,0.0458,0.0482,0.0523,0.0503,0.0482,0.049,0.0485,0.0499,0.0494,0.0438,0.0503,0.049,0.046,0.0516,0.049,0.0521,0.0488,0.0501,0.0495,0.0666,0.0545,0.0465,0.0458,0.0462,0.0489,0.046,0.0447,0.0481,0.0463,0.0488,0.0498,0.0505,0.0445,0.0513,0.0524,0.0515,0.0534,0.0451,0.0508,0.0487,0.0497,0.049,0.0565,0.0502,0.0463,0.0531,0.0479,0.0412,0.0494,0.0518,0.0515,0.0513,0.0491,0.0506,0.052,0.0509,0.0502,0.0507,0.0505,0.0537,0.0434,0.0484,0.0481,0.048,0.0492,0.0497,0.0488,0.0496,0.0465,0.05,0.05,0.049,0.0427,0.0496,0.0522,0.0497,0.0488,0.0501,0.0494,0.0496,0.0452,0.0526,0.0517,0.05,0.0488,0.0447,0.0481,0.0505,0.0497,0.0501,0.0505,0.0489,0.0496,0.0503,0.0497],"Count":500}]