SC, Rev,and RB speed test

Dave Cragg dcragg at lacscentre.co.uk
Fri Apr 16 17:17:56 EDT 2004


At 1:32 pm -0400 16/4/04, Brian Yennie wrote:
>Chris,
>
>Here's one more shot, which uses a pretty simple trick: it first
>crumples everything down into the first two characters of a word and
>does a rough comparison on that. If that passes, then and only then
>does it look for an exact match. It also only considers the first 3
>words of the search string on first pass, which seems fairly optimal
>for weeding out the non-matches.
>
>on mouseUp
>   local stubs,stList,theText,shortList,shortFind,MatchList,sMS,sTicks,w
>   put fld "TargetText" into theText
>   put "" into fld "TheResults"
>   put field "SearchTextList" into stList
>   put the milliseconds into sMS
>   put ticks() into sTicks
>   repeat for each word w in theText
>     put (char 1 to 2 of w) after shortList
>   end repeat
>   repeat for each line stLine in stList
>     put empty into shortFind
>     repeat for each word w in (word 1 to 3 of stLine)
>       put (char 1 to 2 of w) after shortFind
>     end repeat
>     put offset(shortFind, shortList) into tPossible
>     if (tPossible > 0) then
>       if (offset(stLine, theText, tPossible) > 0) then
>         put stLine & cr after MatchList
>       end if
>     end if
>   end repeat
>   put MatchList into fld "TheResults"
>   put the milliseconds - sMS && "ms" & return && "(" &
>ticks()-sticks && "ticks)" & return before cd fld "SpeedRecords"
>end mouseUp

I like this. It cuts the speed by half on my machine. But it has a 
problem with word definition between the target text and the search 
strings. Quoted text in the target text is treated as a single word. 
That can be fixed by just replacing quotes with empty. But even with 
that it was missing a couple of matches. I assume this is either 
where a single character word is followed by punctuation in the 
target text. (e.g. "I,") or where there are quotes in the search 
string. I'm not sure if this can be dealt with easily without making 
big assumptions about the search strings.

Cheers
Dave


More information about the use-livecode mailing list