custom property searching speed question

Alex Tweedly alex at tweedly.net
Wed Mar 2 18:10:50 EST 2005


Richard Gaskin wrote:

> Lynch, Jonathan wrote:
>
>> More tinkering and testing of timing...
>>
>> I changed the customproperty set so that it contains 500,000 records
>> with 3 items in each record.
>>
>> Item 1, the name of the element
>> Item 2, a bunch of words
>> Item 3, a number (100)
>>
>> I created a script that gets the sum of column 3 of this data set - that
>> is, it adds up item 3 for each element.
>>
>> This script:
>>
>> on mouseUp
>>   put the milliseconds into M
>>   put the customproperties of field "theData" into myArray
>>   put 0 into tSum
>>   set the itemdelimiter to numtochar(30)
>>   repeat for each element E in myArray
>>    add item 3 of E to tSum
>>   end repeat
>>   put tSum into field "output"
>>   put ((the milliseconds)-M)/1000 into field "feedback"
>> end mouseUp
>>
>> produces the correct result in .486 seconds!
>>
>> Half a second to sum a column of 500,000 items! 
>
>
> What kind of hardware are you using?  Tests like that usually take me 
> at least 2 seconds on my PBG4/1KHz.

1Khz ?  That's your problem - most of us are using machines measured in 
Mhz or Ghz these days. :-)
The script below (which creates the data as well, so you can see exactly 
what it is doing) takes .236 seconds on my laptop (2.8G Pentium 4)

> Have you tried looping through lines in a combined string? If your 
> results are like mine you'll shave another 20% off.
>
Only saves 4% for me. (And the "combine" took over a second - 500% of 
the summation cost !)

on mouseUp
  local M, myArray
  local i, E, tSum, t
  put empty into field "lockedField"
  put the millisecs into M
  repeat with i = 1 to 500000
    put "a" & i into t
    put t & ",b c d,2" into  myArray[t]
  end repeat
  put the millisecs-M & cr after field "lockedField"
 
  put the millisecs into M
  put 0 into tSum
  repeat for each element E in myArray
    add item 3 of E to tSum
  end repeat
  put ((the milliseconds)-M)/1000 && tSum & cr after field "lockedField"
 
  put the millisecs into M
  combine myArray with cr
  put ((the milliseconds)-M)/1000 & cr after field "lockedField"
 
  put the millisecs into M
  put 0 into tSum
  repeat for each line E in myArray
    add item 3 of E to tSum
    --    put E & cr  after field "lockedField"
  end repeat
  put ((the milliseconds)-M)/1000 && tSum & cr after field "lockedField"
 
end mouseUp




-- 
Alex Tweedly       http://www.tweedly.net



-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 266.5.3 - Release Date: 01/03/2005



More information about the use-livecode mailing list