[622] in Coldmud discussion meeting

root meeting help first first in chain previous in chain previous next next in chain last in chain last

Re: Timer object

daemon@ATHENA.MIT.EDU (Mon Dec 19 09:51:38 1994 )

To: jeffpk@netcom.com (Jeff Kesselman)
Cc: coldstuff@MIT.EDU, zachary@pentagon.io.com
In-Reply-To: Your message of "Sat, 17 Dec 1994 20:01:26 PST."
             <199412180401.UAA18659@netcom13.netcom.com> 
Date: Mon, 19 Dec 1994 08:47:47 -0600
From: Zachary  <zachary@pentagon.io.com>


 >From: jeffpk@netcom.com (Jeff Kesselman)
 >Message-Id: <199412180401.UAA18659@netcom13.netcom.com>
 >Subject: Timer object
 >To: coldstuff@MIT.EDU
 >Date: Sat, 17 Dec 1994 20:01:26 -0800 (PST)
 >X-Mailer: ELM [version 2.4 PL23]
 >Mime-Version: 1.0
 >
 >
 > I've written a first pass at a simpel timer object.  The idea was a 
 > minimal suite of functionality to allow 'system independance' of functions
 > that need a timed call back.  
 > 
 > Its small and should be pretty self-explanatory.  It supports two kinds 
 > of call backs, a one-shot (called an alarm) and a periodic (called a clock.)
 > 
 > How close the timing is to the timign asked for is a function of the 
 > period of the heartbeat.  You need to put a call to $timer.pulse() in the 
 > system heartbeat function.
 >
 > Its quite possible that there are more efficient ways to do what I
 > am doing, particularly in the resetting of a clock callback.  If someone
 > can suggest better code, Ild be more then happy to use it.
 >
 > All comments are welcome.
 >
 > Jeff Kesselman

 [ code omitted ]

 looks okay, but I think you can make it a bit more efficent in the average case by
 keeping the list of callbacks in order from soonest to latest - this changes your
 check each tick to O(1) (ie constant time to check to see if just the first thing has
 happened yet) at the expense of making your inserts O(n) with n the length of the list.
 Average insert case is then actually O(n/2), but who's counting?

 This should not be taken as a criticism of your code in any way - it looks good and it's
 nice to see people writing Cold code and sharing it :)  Keep up the good work!

 --Zachary