Speed optimisation

Kay C Lan lan.kc.macmail at gmail.com
Thu Oct 6 02:16:44 EDT 2005


On 10/5/05, Alex Tweedly <alex at tweedly.net> wrote:

Amazing how much it helps to be slow in replying, you get to use the
> best ideas from all previous entries :-)
>
> It's one less statement than Sarah's (though more characters) so it
> competes for shortest.
>
> On my machine (for 150,000),
> Dick's method took 3.76 seconds
> Alex's method took 2.43 seconds
>
>
> function addDivandFormat pTime,pSeconds
> set the itemDelimiter to ":"
> put item 1 of pTime * 3600 + item 2 of pTime * 60 + item 3 of pTime +
> pSeconds into tSeconds
> return format("%02d:%02d:%04.1f", tSeconds div 3600, tSeconds mod 3600
> div 60, tSeconds mod 60)
> end addDivandFormat



I certainly have to agee with Alex's statement about sitting back and
watching. So here is my effort:

I've got the same amount of lines as Sarah's but more words; but less word's
than Alex's, assuming you set the twelveHourTime in an openStack handler.

-------
set the twelveHourTime to false --possibly set in openStack handler

function addTime pTime,pSeconds
--set the twelveHourTime to false (if not set elsewhere in stack)
set the itemDelimiter to "."
convert item 1 of pTime to seconds
convert (item 1 of pTime + pSeconds) to long time
return it & "." & item 2 of pTime
end addTime

for 150000 calculations on my machine (run 3 consecutive times)

IF the original time has no decimal ie 10:30:28
Dick 5.78, 5.83, 5.86
Alex 5.38, 5.73, 5.45
me 5.48, 5.46, 5.55

With decimal times ie 11:23:34.6
Dick 6.05, 6.21, 6.13
Alex 5.55, 5.65, 5.68
me 5.4, 5.46, 5.58

Dick's and Alex's seem to prefer no decimal, but mine doesn't seem fussed
either way.

So do I win the Cupie doll? ;-)



More information about the use-livecode mailing list