You can always measures the time it takes to run script blocks and cmdlets
or script files
by using measure-command
Type "help Measure-Command -examples" to get some examples.
As for the performance, I'd choose option 3. It will pipe line by line instead
of reading
the whole file and than start to pipe (option 1,2)
Shay
http://scriptolog.blogspot.com
> I have a powershell script that needs to read a big file and I want to
> make sure not to be "out of memory" so I thought three ways to read
> the file line by line:
>
> (1) $f = get-content bigfile.txt; $f | foreach { ...}
> (2) get-content bigfile.txt | foreach {...}
> (3) get-content bigfile.txt | foreach-object {...}
> (4) $f = openfile(bigfile); while ($line = readline(f$)) do {...};
> closefile($f)
> (Yes, I know that (4) is syntactically incorrect, I show it just to
> make my point)
>
> I'm definitively sure that (1) will read all the file at one chunk.
> But how about the (2) and (3)?
> The (4) is the way traditional programming languages do it and it
> reads line
> by line.
> Is there any way to implement (4) in PowerShell?
> Any help would be appreciated. Thanks.
>
> Regards,
> Freddy Chavez.