an addition test

Richard Crispin rcrispin at
Tue Dec 18 15:32:01 EST 2001

Hi All
    I have a program that summarizes some log files. One of the things 
it does is to add up all of the bytes sent for each record. I found 
this to be painfully slow. I was investigating a way to speed it up 
(see the scripts listed below).
    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 
    I love experimenting.

on mouseup
   -- force the 3 methods to be compiled
   put AddColumn1(0) into TB1
   put AddColumn2(0) into TB2
   put AddColumn3(0) into TB3
   -- set all the defaults
   put 0 into tb1
   put 0 into tb2
   put 0 into tb3
   put fld "Bytes" into theBytes
   -- start the timing
   put the ticks into s0
   put AddColumn1(theBytes) into TB1
   put the ticks into s1
   put AddColumn2(theBytes) into TB2
   put the ticks into s2
   put AddColumn3(theBytes) into TB3
   put the ticks into s3
   -- report the details - Time and Total to be sure the totals are all the same
   put s1 - s0 &&tb1 & "   " & s2 - s1 &&tb2 & "   " & s3 - s2 &&tb3
end mouseup

Function AddColumn1 TheValues
   put 0 into thetotal
   put the number of lines in Thevalues into MaxL
   repeat with L = 1 to MaxL
     add line L of theValues to theTotal
   end repeat
   return theTotal
end AddColumn1

Function AddColumn2 TheValues
   put 0 into thetotal
   set the itemdelimiter to return
   put the number of items in Thevalues into MaxL
   repeat with L = 1 to MaxL
     add item L of theValues to theTotal
   end repeat
   return theTotal
end AddColumn2

Function AddColumn3 theValues
   replace return with "," in thevalues
   set the itemdelimiter to ","
   put sum(theValues) into theTotal
   return theTotal
end AddColumn3
Richard Crispin                    e-mail:rcrispin at
Psychology,University of Waterloo  phone:Days (519)885-1211 ext. 5669
200 University Ave. W                    Touch Tone (519)888-4567 5669
Waterloo, Ont.  Canada   N2L 3G1   FAX:(519)746-8631
When I die I'd like to die the way my grandfather died, peacefully in
his sleep...      ... not screaming and shouting, like his passengers.

"Boot, you transistorized tormentor! Boot!"~Archibald Asparagus, VeggieTales

"Time, heat and pressure.
   The same things that make a diamond also make a waffle."~Scott Meyer

More information about the Use-livecode mailing list