SC, Rev,and RB speed test

Monte Goulding monte at sweattechnologies.com
Sat Apr 17 21:46:07 EDT 2004


Ok this script produces the same results (note moved to milliseconds because
ticks is starting to get to gross now) but it will handle changes to either
the search list or the target text with optimal speed:

local sMatch,sOldMatch,sSearch,sOldSearch,sLongLines

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 the milliseconds into tTicks
  put field "targetText" into tMatchList
  put field "SearchTextList" into tList
  if tMatchList <> sOldMatch then
    put tMatchList into sOldMatch
    put "" into sMatch
    -- 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
  if tList <> sOldSearch then
    put tList into sOldSearch
    put "" into sSearch
    put "" into sLongLines
    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 sSearch[inLine]
      else
        put inLine & cr after sLongLines
      end if
    end repeat
    delete char -1 of sLongLines
  end if
  put sSearch into tSearch
  repeat for each line inLine in sLongLines
    if inLine is in tMatchList then
      put inLine & return after MatchList
    end if
  end repeat
  -- Now for the Revolution!
  intersect tSearch with sMatch
  put keys(tSearch) & cr & MatchList into field "TheResults"
  put the milliseconds-tTicks && "milliseconds" &cr after fld "SpeedRecords"
end mouseUp

The following code is optimized for only three word search lists and
produces astounding results on second and subsequent searches of 14
milliseconds (the fiirst search is 487 milliseconds which is probably about
30-35 ticks???):

local sMatch,sOldMatch,sSearch,sOldSearch

on mouseUp
  local tFind,tSearch,tLine,tMatchList, \
      	 tTicks,tList,k1,k2,k3,inWord,inLine
  set cursor to watch
  put empty into field "TheResults"
  put the milliseconds into tTicks
  put field "targetText" into tMatchList
  put field "SearchTextList" into tList
  if tMatchList <> sOldMatch then
    put tMatchList into sOldMatch
    put "" into sMatch
    -- 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
  if tList <> sOldSearch then
    put tList into sOldSearch
    put "" into sSearch
    replace quote with empty in tList
    repeat for each line inLine in tList
       put true into sSearch[inLine]
    end repeat
  end if
  put sSearch into tSearch
  -- Now for the Revolution!
  intersect tSearch with sMatch
  put keys(tSearch) into field "TheResults"
  put the milliseconds-tTicks && "milliseconds" &cr after fld "SpeedRecords"
end mouseUp

Cheers

Monte



More information about the use-livecode mailing list