I updated my clock and tested the cpu time again. I must have slipped a tick or something, because now I get 1.5% cpu with the simple script and 0.8% cpu with my time saving script. Much more like I though it should be. I am happy with either one, so I put both scripts in the clock in my user space.

Dennis

on openCard
  setTime2 --set to which script to run
end openCard

on setTime1 --this is the simplest script (1.5%)
  --put the long seconds into ST
  put word 1 of the long time into T --8:13:15
  put T into fld "Time" --8:13:15.000
  split T using ":" --make array of the 3 numbers
set the angle of grc "Hour" to 360+90-(30*T[1]) - trunc(T[2]/2) -- angles in even degrees
  set the angle of grc "Minute" to 360+90-(6*T[2]) - trunc(T[3]/10)
  set the angle of grc "Second" to 360+90 - 6*T[3]
send "setTime1" to me in 1-(the long seconds mod 1) seconds --time left to next second
  --put (((the long seconds)-ST)*100)&"% cpu"
end setTime1

on setTime2 --this script uses less CPU time (0.8%)
  --put the long seconds into ST
  put word 1 of the long time into T --8:13:15
  put T into fld "Time" --8:13:15.000
  split T using ":" --make array of the 3 numbers
  get 360+90-(30*T[1]) - trunc(T[2]/2) --angle of the hour "hand"
if (the angle of grc "Hour") <> it then set the angle of grc "Hour" to it
  get 360+90-(6*T[2]) - trunc(T[3]/10) --angle of the minute "hand"
if (the angle of grc "Minute") <> it then set the angle of grc "Minute" to it
  set the angle of grc "Second" to 360+90 - 6*T[3]
send "setTime2" to me in 1-(the long seconds mod 1) seconds --time left to next second
  --put (((the long seconds)-ST)*100)&"% cpu"
end setTime2


On May 31, 2005, at 10:12 AM, Geoff Canyon wrote:

On May 31, 2005, at 6:05 AM, Dennis Brown wrote:


I can't say that I would make the tradeoff of the extra lines of code for a few microseconds, but I really like the split idea --it shows another concept in a simple way and makes the script look even simpler. I updated my clock with it. Good thinking!


I agree that the tradeoff is of arguable benefit. Having to use local variables is another drawback in favor of just comparing to the startAngle. Using local variables is habit because I end up in this situation with text in a field much more often than with the startAngle of a graphic. Text in a field is much slower in comparison -- the startAngle is acceptably fast.

Thanks re: the split command. I don't remember when that first occurred to me, but I was pretty pleased with myself that day too ;-)

_______________________________________________
use-revolution mailing list
use-revolution@lists.runrev.com
http://lists.runrev.com/mailman/listinfo/use-revolution


_______________________________________________
use-revolution mailing list
use-revolution@lists.runrev.com
http://lists.runrev.com/mailman/listinfo/use-revolution

Reply via email to