;;; 7/18/2001 Alexander Repenning ;;; 12/12/08 Clozure CL ;;; Nano Second Timer ;;; works for intel macs ;;; Hemlock Editor Extension: Ctrl-x Ctrl-t will show the time is takes to compute the ;;; current form selected in an editor buffer. Time is in nano seconds ;;; unlike a previous version of this code called hires timer, code will be executed ;;; only once. (in-package :hemlock) (export '(time-to-run)) (defvar *mach-time-unit-ratio* (ccl::rlet ((info #>mach_timebase_info)) (#_mach_timebase_info info) (/ (ccl::pref info #>mach_timebase_info.numer) (ccl::pref info #>mach_timebase_info.denom)))) (eval-when (:compile-toplevel :load-toplevel :execute) (defmacro TIME-TO-RUN (&body Form) " in: &body Form {t}. Measure the time is takes to run
in Nano seconds. Form will run only ONCE." `(locally (declare (optimize (speed 3) (safety 0))) (ccl::without-interrupts (let (t2 t3 t4) (setq t2 (#_mach_absolute_time)) ;; prime/cache the call: otherwise delta time will be significantly larger between first two calls (setq t2 (#_mach_absolute_time)) ,@Form (setq t3 (#_mach_absolute_time)) (setq t4 (#_mach_absolute_time)) (values (round (* (max (- t3 t2 (- t4 t3)) 0) *mach-time-unit-ratio*)))))))) (defun PRINT-TIME (Time &optional (S t)) " in: Time {float} time in seconds, &optional S {stream} default t. Print