Guys I thought I'd speed test these.

Unfortunately I don't have the time to figure out exactly how Geoff's
amended version of Peter's solution actually works in this case; rounding
1.1 to 1.25, 3.3 to 3.5. I can get it to work with whole numbers, but not
0.25 increments as per the OP.

The current script produces:

For 10000 cycles
K's solution = 25ms
Paul's solution = 28ms
Geoff's solution for = 39ms
Geoff's solution doesn't = K's
Geoff's solution doesn't = Paul's

Please amend the script below:

on mouseUp
   put 10000 into tRepeats
   --to create a list of times to use.
   --900 is used as fixed 1/4 hour interval
   repeat tRepeats times
      put 1329494400 & "," & \
            (1329494400 + random(36000)) & "," & \
            900 & cr after tStore
   end repeat

   --K solution
   put the millisec into tStartClock
   repeat for each line tLine in tStore
      put item 1 of tLine into tStartTime
      put item 2 of tLine into tEndTime
      put item 3 of tLine into tIncrement
      put round(((tEndTime + (tIncrement/2) - 1 -
tStartTime)/tIncrement),0)/(3600/tIncrement) & cr after tStore2
   end repeat
   put the millisec into tEndClock
   put tEndClock - tStartClock into tTotalTime1

   --Paul's  max solution
   put the millisec into tStartClock
   repeat for each line tLine in tStore
      put item 1 of tLine into tStartTime
      put item 2 of tLine into tEndTime
      put item 3 of tLine into tIncrement
      put
round(((tEndTime-tStartTime)/max(tIncrement,60))+0.4999,0)/(3600/max(tIncrement,60))
& cr after tStore3
   end repeat
   put the millisec into tEndClock
   put tEndClock - tStartClock into tTotalTime2
   if (tStore2 <> tStore3) then
      put "Paul's solution doesn't = K's" & cr after tErrors
   end if

   --Geoff's itemoffset solution
   put the millisec into tStartClock
   repeat for each line tLine in tStore
      put item 1 of tLine into tStartTime
      put item 2 of tLine into tEndTime
      put item 3 of tLine into tIncrement
      put (tEndTime - tStartTime)/tIncrement into x
      put 4 into i --tried 900, 4, 25 and 0.25
      put (x div i*i) + (item itemOffset((x mod i > 0),"true,false") of
(i,0)) & cr after tStore4
   end repeat
   put the millisec into tEndClock
   put tEndClock - tStartClock into tTotalTime3
   if (tStore2 <> tStore4) then
      put "Geoff's solution doesn't = K's" & cr after tErrors
   end if
   if (tStore3 <> tStore4) then
      put "Geoff's solution doesn't = Paul's" & cr after tErrors
   end if
   put "For " & tRepeats & " cycles" & cr into msg
   put "K's solution = " & tTotalTime1 & "ms" & cr after msg
   put "Paul's solution = " & tTotalTime2 & "ms" & cr after msg
   put "Geoff's solution for = " & tTotalTime3 & "ms" & cr after msg
   put tErrors after msg
end mouseUp
_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to