Reading Text Files Fast

by Dec 28, 2010

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.

Twitter This Tip!
ReTweet this Tip!