;;; 7/18/2001 Alexander Repenning ;;; 12/07/08 Clozure CL ;;; Micro 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 micro seconds ;;; unlike a previous version of this code called hires timer, code will be executed ;;; only once. (in-package :hemlock) (export '(time-to-run)) (eval-when (:compile-toplevel :load-toplevel :execute) (ccl:use-interface-dir :carbon) (ccl:open-shared-library "/System/Library/Frameworks/Carbon.framework/Carbon")) (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 Microseconds. Form will run only ONCE." `(locally (declare (optimize (speed 3) (safety 0))) (ccl::without-interrupts (ccl:rlet ((t1 :unsigned-long) (t2 :unsigned-long) (t3 :unsigned-long) (t4 :unsigned-long)) (#_Microseconds t1) ;; Cache the trap call (#_Microseconds t1) ,@Form (#_Microseconds t2) (#_WideSubtract t2 t1) ;; compensate overhead time (#_Microseconds t3) (#_Microseconds t4) (#_WideSubtract t4 t3) (- (+ (ccl:rref t2 :wide.lo) (* #.(expt 2 32) (ccl:rref t2 :wide.hi))) (+ (ccl:rref t4 :wide.lo) (* #.(expt 2 32) (ccl:rref t4 :wide.hi))))))))) (defun PRINT-TIME (Time &optional (S t)) " in: Time {float} time in seconds, &optional S {stream} default t. Print