[fpc-pascal]Word count function

James_Wilson at i2.com James_Wilson at i2.com
Mon Oct 1 22:41:16 CEST 2001


>>  DELIMITERS = ' .,!?_-)}]>;:=@/\#9';
>Replace the string by a set, this is much faster:
>DELIMITERS : set of char = [' 

>if StringToCheck [succ (Index)] in DELIMITERS then
>should beat the pos call easily

Much faster? Boy, was that an understatement. The original version I had 
posted checked an entire 30 meg ASCII text file in a pathetic 2 minutes. 
Simply making the 2 changes above that you had suggested dropped that to a 
mind-blowing 4 seconds! That's a staggering difference. But I must confess 
that I don't know exactly why there would be such a huge difference. Why 
is a "set of char" soooo much faster then a const?

>while (Index < LineLength) and (CurrentChar in 
['A'..'Z','a'..'z','0'..'9']) do
>might be faster as well

This was certainly cleaner looking then what I had posted, but I can't 
honestly tell if it makes much difference because the previous update was 
so fast it left little room for improvement!  :-)

Thanks much for the tip...

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20011001/8d775fed/attachment.html>

More information about the fpc-pascal mailing list