SC, Rev,and RB speed test
Monte Goulding
monte at sweattechnologies.com
Sat Apr 17 21:10:18 EDT 2004
> Hope this is interesting, not to mention helpful.
Very interesting and remarkable ;-)
This can be still further optimised in a two ways:
- declare all variables (this saves a few milliseconds)
- turn tMatch into a script local and determine if it has changed so as to
cut some of the prep time on subsequent attempts
The result is something like this:
local sMatch,sOldMatch
on mouseUp
local tFind,tSearch,tLine,tMatchList, \
tTicks,tList,k1,k2,k3,inWord,inLine ,MatchList
set cursor to watch
put empty into field "TheResults"
put ticks() into tTicks
put field "targetText" into tMatchList
put field "SearchTextList" into tList
--if tMatchList <> sOldMatch then
--put tMatchList into sOldMatch
-- stripping quotes from both sets saves problems with single quotes
-- or with quoted strings being treated as a word
replace quote with empty in tMatchList
-- Prepare the target text in all consecutive triplet groups
repeat for each word inWord in tMatchList
put k2 into k1
put k3 into k2
put inWord into k3
put true into sMatch[k1 && k2 && k3]
end repeat
--end if
replace quote with empty in tList
repeat for each line inLine in tList
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 sMatch
put keys(tSearch) & cr & MatchList into field "TheResults"
put ticks()-tTicks && "ticks" &cr after fld "SpeedRecords"
end mouseUp
PS There seems to be only 2 lines with > 3 words per line. If these were
removed from the search text list it would enable tSearch to be moved to a
script local too and allow for much faster second and subsequent runs.
Results of this version are 39 ticks on first run and 35 ticks on subsequent
runs without changing the data.
Cheers
Monte
More information about the use-livecode
mailing list