Created
January 7, 2016 06:41
-
-
Save midnightfreddie/d3173f551f19521dd714 to your computer and use it in GitHub Desktop.
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
# 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