Senin, 14 Februari 2011

Powershell - Powertips: Reading Text Files Fast

I get emails from powershell.com that are worth sharing (and remembering). These are not my scripts. Signup for daily PowerTips here: http://powershell.com/cs/.

Let's assume you want to read a large text file. Let's create one:

Get-Process | Export-CLiXML $home\data.xml

(Dir $home\data.xml | Select-Object –expandProperty Length)/1MB
It should be roughly 5MB in size. Now let's read it using Get-Content:
Measure-Command { Get-Content $home\data.xml }
Now, you should check this out:
Measure-Command { [System.IO.File]::ReadLines(“$home\data.xml“) }
You will find the second approach is 20 times faster

0 komentar:

Posting Komentar

 
Powered by Blogger