[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Measuring elapsed CPU time



In article <1jlr7cINNep1@mensa.usc.edu> joungwoo@mensa.usc.edu (John Kim) writes:

	   So I tried using builtin function GET-INTERNAL-RUN-TIME as follows,
   but the following function defined by me usually it gives me either 0 or 1 no
   matter how time-consuming task I give it. 

   (defun CPU-time (form)
     "returns the actual elapsed CPU(?) time not including I/O processing 
   in msecs.
   "
     (let ((start-time nil)
	   (end-time nil)
	   )
       (setq start-time (get-internal-run-time))
       form
       (setq end-time (get-internal-run-time))
       (print start-time)
       (print end-time)
       (- end-time start-time)
       ))

   Am I doing something wrong in the above function definition or is there a
   better way to do this?

this sort of thing needs a macro.  in your construct, the form has been evaled by the time
the function starts, and all your timer ends up timing is how long it takes the
evaluator to find the value of the symbol "form".  try this:

(defmacro CPU-time (form)
  `(let (start-time end-time)
     (setq start-time (get-internal-run-time))
     ,form
     (setq end-time (get-internal-run-time))
     (print start-time)
     (print end-time)
     (- end-time start-time)))
--
Hume Smith                                Honour sick and davey cris-cross
hume.smith@acadiau.ca                     McTruloff sentimie
emcoop@bnr.ca                             A parsnip inner pair threes.