[futurebasic] Re: [FB] word count routine

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : September 2001 : Group Archive : Group : All Groups

From: Jay Reeve <jktr@...>
Date: Sat, 22 Sep 01 03:04:18 -0500
>- this looks faster, is it?
Jonathan,

You know how I like a speed challenge, so I took some time this evening 
(who needs sleep, anyway?) to optimize the word counter for speed. I 
think this should satisfy you. It's more than twice as fast as what I 
sent before. On my slow (240mHz) old G3, it will count the KJ Bible in 
under 1/3 second. I think it LOOKS more streamlined, too. :-)

clear local mode
dim as str255        myType  
dim as unsigned long myCount, myEnd
dim as ptr           myPtr   
local fn wordCount7( theContH as hndl )
'Specify delimiters here
myType[  9 ] = 1
myType[ 13 ] = 1
myType[_" "] = 1
'
myPtr = [ theContH ]
myEnd = myPtr + fn gethandlesize( theContH ) - 1
for myPtr = myPtr to myEnd
if myType[ myPtr.0`` ] = ( myCount and 1 ) then myCount ++
next
end fn = ( myCount + 1 ) / 2

BTW, I was a little surprised to find that using myStr$[x] is MUCH faster 
than myArray``(x).

 0"0
 =J= a  y
  "