an addition test

Richard Crispin rcrispin at watarts.uwaterloo.ca
Wed Dec 19 13:24:01 EST 2001


>
>Message: 11
>Date: Tue, 18 Dec 2001 17:21:24 -0800
>To: use-revolution at lists.runrev.com
>From: "Geoff Canyon" <gcanyon at inspiredlogic.com>
>Subject: Re: an addition test
>Reply-To: use-revolution at lists.runrev.com
>
>At 3:30 PM -0500 12/18/01, Richard Crispin wrote:
>>    The data I used was a column of 38,497 numbers ranging from 0 to 
>>about 750,000,000. The first method involved adding each line to a 
>>total this took 3,179 ticks. The second method involved using the 
>>return as the item delimiter and adding each item to a total this 
>>took 4,632 ticks. I was not happy with these results so I tried 
>>using the Replace command to replace the returns with a comma and 
>>then using the Sum command. This took an amazing 3 ticks. A 
>>considerable savings.
>>    I love experimenting.
>
>I love experimenting as well. I'm betting sum is absolutely the way 
>to go. This solution certainly won't take 3 ticks, but I bet it will 
>be substantially faster than either of the other two solutions you 
>mentioned:
>
>Function AddColumn4 TheValues
>   put 0 into theTotal
>   repeat for each line L in TheValues
>     add L to theTotal
>   end repeat
>   return theTotal
>end AddColumn2
>
>The "repeat for each" loop is _much_ faster than any other loop, 
>especially for very large lists such as you are working with.
>
>That said, Sum is definitely the way to go. :-)
>
>regards,
>
>Geoff

The results I got doing another test including Geoff's suggestion were
Using Lines: 2781 ticks
Using Items: 4208 ticks
Using Replace and Sum: 3 ticks
Using Repeat for each: 7 ticks

Richard



More information about the Use-livecode mailing list