Skip to content

Instantly share code, notes, and snippets.

@midnightfreddie
Created January 7, 2016 06:41
Show Gist options
  • Save midnightfreddie/d3173f551f19521dd714 to your computer and use it in GitHub Desktop.
Save midnightfreddie/d3173f551f19521dd714 to your computer and use it in GitHub Desktop.
# An illustration of what does and doesn't slow down Powershell and why
function Get-LotsOfData {
param (
$Rows = 10000
)
# $OneK is a 1024-character string that is just the alphabet repeating
$OneK = ( 0..1023 | ForEach-Object { [char](65 + $_ % 26) } ) -join ""
1..$Rows | ForEach-Object {
# Emit the equivalent of one row of a CSV with 5 columns
$Properties = [ordered]@{
Index = $_
This = $OneK
That = $OneK
The = $OneK
Other =$OneK
}
New-Object psobject -Property $Properties
}
}
Measure-Command {
Get-LotsOfData |
Export-Csv -NoTypeInformation .\deleteme.csv
}
Measure-Command {
Get-LotsOfData |
Sort-Object -Property Index |
Export-Csv -NoTypeInformation .\deleteme2.csv
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment