an addition test

Geoff Canyon gcanyon at inspiredlogic.com
Tue Dec 18 20:23:01 EST 2001


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




More information about the use-livecode mailing list