Speed optimisation

Geoff Canyon gcanyon at inspiredlogic.com
Wed Oct 5 05:18:44 EDT 2005


I wrote the following alternative. It's about twice as fast, which is  
less than I had hoped for. One real speed gain if your data is at all  
repetitive would be to memo-ize your function. Keep a table of a few  
thousand inputs and outputs. Whenever you get a call with the same  
values that you've done before, you'll have the answer as quickly as  
an array lookup. Obviously if your data isn't repetitive this doesn't  
help. It seems like a good guess when calling a routine 150,000 times  
that you'll be calling it with the same arguments a few times.

regards,

geoff

function newTime T,pSeconds
   split T using ":"
   add pSeconds to T[3]
   repeat with i = 3 to 2 step -1
     get T[i] div 60
     subtract 60 * it from T[i]
     add it to T[(i-1)]
   end repeat
   repeat with i = 1 to 3
     if T[i] < 10 then put "0" before T[i]
   end repeat
   return T[1] & ":" & T[2] & ":" & T[3]
end newTime


On Oct 4, 2005, at 11:58 PM, Rob Beynon wrote:

> Dear Colleagues,
>
> I have a function that takes a time in this format
>
> hh:mm:ss.s
>
> and to which I add a variable number of seconds, then output the
> updated time in the same format. hh can be greater than 24!
>
> Here's the function. Problem is, it seems slow (I need to do this call
> about 150,000 times each file I process). I would appreciate any
> insights into making this function faster
>
> function newTime oldTime,addedSec
>     put the replacetext(oldTime,":"," ") into splitTime
>     put the first word of splitTime into h
>     put the second word of splitTime into m
>     put the third word of splitTime into s
>     put s + addedSec into newSec
>     put newSec mod 60 into remainSec
>     put (newsec-remainSec)/60 into addedMin
>     put m + addedMin into newMin
>     put newMin mod 60 into remainMin
>     put (newMin-remainMin)/60 into addedHr
>     put h + addedHr into newHr
>     if length(remainSec) = 1 then put "0" & remainSec into remainSec
>     if length(remainMin) = 1 then put "0" & remainMin into remainMin
>     if length(newHr) = 1 then put "0" & newHr into newHr
>     put newHr & ":" & remainMin & ":" & remainSec into newTime
>     return newTime
> end newTime
>
> -- 
> All best wishes,
> Rob
>
> (Created at 07:55 on 05/10/2005)
>
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
>




More information about the use-livecode mailing list