Skip to content

Instantly share code, notes, and snippets.

@liamjpeters
Created October 1, 2025 21:06
Show Gist options
  • Select an option

  • Save liamjpeters/1bfd139d1e1dd0c198636eb680f9f142 to your computer and use it in GitHub Desktop.

Select an option

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
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