[PS] Poor performance



I wanted to count number of semicolons in a text file. This file is quite large (498 238 bytes) but I expected PowerShell to parse in a few seconds. Instead of seconds I got minutes. I don't know whether .NET overhead is the cause or there is a bug in my implementation.

PS> $a=gc a.eml
PS> $b=0
PS> date
PS> $a | foreach { for($i=0;$i -lt $_.length;$i++) { if($_[$i] -eq ";") { $b++ } } } ; $b ;
PS> date

16 maja 2006 19:44:21
1442
16 maja 2006 19:48:26

--
Grzegorz Niemirowski, Poland, Europe
www.grzegorz.net
Uptime: 1 day, 4 hours, 22 minutes and 10 seconds

.