tick and tock functions



Hello, I'm planning to commit the following unless I hear otherwise.

tick: set t0 equal to now
tock: return now minus t0

get-internal-run-time and get-internal-real-time are CL functions
and internal-time-units-per-second is a CL special variable.

Code works as advertised with Maxima + Clisp 2.39, GCL 2.6.7,
and SBCL 1.0 on Linux (ignoring any differences in timekeeping
on the part of the Lisp implementation).

Hope this helps,
Robert Dodier

--- src/macsys.lisp 11 Aug 2006 05:01:04 -0000  1.52
+++ src/macsys.lisp 26 Dec 2006 21:26:26 -0000
@@ -573,3 +573,42 @@
   (format t "~&~%Automatically continuing.~%To reenable the Lisp
debugger set *debugger-hook* to nil.~%")
   (throw 'return-from-debugger t))

+; tick and tock functions --
+; tock() returns time elapsed (in seconds) since most recent tick().
+; Notes: (1) tock returns both run time and real time.
+; (2) tock returns Maxima rationals.
+; (3) tick returns [0, 0].
+
+#|
+(%i1) display2d : false;
+(%o1) false
+(%i2) load ("./ticktock.lisp");
+(%o2) ?\.\/ticktock\.lisp
+(%i3) tick ();
+(%o3) [0,0]
+(%i4) tock ();
+(%o4) [0,6435543/1000000]
+(%i5) tock ();
+(%o5) [0,16459571/1000000]
+(%i6) (tick (), factor (exp (1729*x) - 1), tock ());
+(%o6) [161/100,201793/125000]
+(%i7) ''%, float;
+(%o7) [1.61,1.614344]
+(%i8) tock ();
+(%o8) [161/100,13639803/1000000]
+(%i9) ''%, float;
+(%o9) [1.61,13.639803]
+|#
+
+(let ((t0-run-time 0) (t0-real-time 0))
+
+  (defun $tick ()
+    (setq t0-run-time (get-internal-run-time))
+    (setq t0-real-time (get-internal-real-time))
+    '((mlist) 0 0))
+
+  (defun $tock ()
+    `((mlist)
+      ,(m// (- (get-internal-run-time) t0-run-time)
internal-time-units-per-second)
+      ,(m// (- (get-internal-real-time) t0-real-time)
internal-time-units-per-second))))
+