SC, Rev,and RB speed test
David Vaughan
dvk at dvkconsult.com.au
Sat Apr 17 03:48:52 EDT 2004
On 17/04/2004, at 5:36, Chris Yavelow <Chris at yav.com> wrote:
>
> ... In the meantime, I did put some realistic data up on my speedtest
> page:
> http://www.yav.com/speed.html
>
I took Chris data and examined it. My solution below exploits that
knowledge of the data but if it is genuinely a typical search set (most
search material being three words or so) then the following does the
trick.
Using the algorithm on Chris' web page I process the material in 530
ticks on my machine (Chris does it in 494). With the code below this is
cut to 51 ticks so it should run in <50 ticks on Chris' machine, an
all-time record.
The trick is to exploit "intersect" (look it up) which is amazingly
fast at, er, intersecting. The intersection itself executes in around
50 milliSeconds or about 3 ticks. It is all the preparatory work which
takes the other 48 ticks.
on mouseUp
-- local tFind,tSearch,tLine,tMatchList, sMS, sTicks
set cursor to watch
put empty into field "TheResults"
put the milliseconds into sMS
put ticks() into sTicks
put field "SearchTextList" into stList
put field "targetText" into tMatchList
-- stripping quotes from both sets saves problems with single quotes
-- or with quoted strings being treated as a word
replace quote with empty in stList
replace quote with empty in tMatchList
-- Prepare the target text in all consecutive triplet groups
put empty into k1
put empty into k2
repeat for each word inWord in tMatchList
put k2 into k1
put k3 into k2
put inWord into k3
put true into tMatch[k1 && k2 && k3]
end repeat
repeat for each line inLine in stList
if the number of words of inLine = 3 then
put true into tSearch[inLine]
else
-- Do a simple search for groups other than three words
if inLine is in tMatchList then
put inLine & return after MatchList
end if
end if
end repeat
-- Now for the Revolution!
intersect tSearch with tMatch
put keys(tSearch) & cr & MatchList into field "TheResults"
put the milliseconds - sMS && "ms" & return && "(" & ticks()-sticks
&& "ticks)" & return before field "SpeedRecords"
end mouseUp
Hope this is interesting, not to mention helpful.
regards
David
> Thanks for the comments,
> Chris
More information about the use-livecode
mailing list