Created
October 1, 2025 21:06
-
-
Save liamjpeters/1bfd139d1e1dd0c198636eb680f9f142 to your computer and use it in GitHub Desktop.
Function to generate a ps1 file full of Hashtables to stress test Hashtable alignment
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
| function Generate-HashtableStressTest { | |
| param ( | |
| [Parameter()] | |
| [int] | |
| $NumHashtables = 500, | |
| [Parameter()] | |
| [int] | |
| $NumEntriesPerTable = 100, | |
| [Parameter()] | |
| [ValidateNotNullOrEmpty()] | |
| [string] | |
| $OutPath = $( | |
| Join-Path -Path $PSScriptRoot -ChildPath "HashtableBenchmark.ps1" | |
| ) | |
| ) | |
| $sb = [System.Text.StringBuilder]::new() | |
| foreach ($i in 1..$NumHashtables) { | |
| $sb.AppendLine("`$hashtable$i = @{") | Out-Null | |
| foreach ($j in 1..$NumEntriesPerTable) { | |
| $padding = "a"*(Get-Random -Minimum 1 -Maximum 5) | |
| $sb.AppendLine("`t'Key$j-$padding' = 'Value$j'") | Out-Null | |
| } | |
| $sb.AppendLine("}") | Out-Null | |
| } | |
| $sb.ToString() | Out-File -FilePath $OutPath -Encoding UTF8 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment