[nio-cvs] r47 - branches/home/psmith/restructure/src/compat

psmith at common-lisp.net psmith at common-lisp.net
Sat Jan 20 21:18:31 UTC 2007


Author: psmith
Date: Sat Jan 20 16:18:31 2007
New Revision: 47

Modified:
   branches/home/psmith/restructure/src/compat/utils.lisp
Log:
Added high res timer

Modified: branches/home/psmith/restructure/src/compat/utils.lisp
==============================================================================
--- branches/home/psmith/restructure/src/compat/utils.lisp	(original)
+++ branches/home/psmith/restructure/src/compat/utils.lisp	Sat Jan 20 16:18:31 2007
@@ -36,3 +36,25 @@
 
 (defun get-readable-time ( &optional (time (get-universal-time)))
   (get-readable "~A/~2,'0d/~2,'0d ~2,'0d:~2,'0d:~2,'0d" time))
+
+
+;;High res timer
+
+(let ((internal-base (get-internal-real-time))
+      (universal-base (get-universal-time)))
+;
+; Gets the time including milliseconds by using a base time from universal time and 
+; tracking high res passing of time using the get-internal-real-time
+; Probably not that accurate in absolute terms i.e. may drift from the base, 
+; but good enough for performance timings
+;
+  (defun get-universal-high-res()
+    (let ((current-internal (get-internal-real-time)))
+      (+ universal-base (/ (- current-internal internal-base) internal-time-units-per-second) )))
+
+  (defun get-readable-high-res()
+    (let ((estimated-universal-float (get-universal-high-res)))
+      (multiple-value-bind (estimated-universal estimated-universal-rem) (floor estimated-universal-float)
+	(format nil "~A.~3,'0d"(get-readable-time estimated-universal) (* 1000 estimated-universal-rem)))))
+  
+  )
\ No newline at end of file



More information about the Nio-cvs mailing list