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

Measuring elapsed CPU time



I'm trying to measure teh elasped CPU time during a lisp form has been run.
The problem with the Common Lisp's builtin function TIME is that it does not
return the various elapsed times but returns the return value of the form
(ie, TIME's arg) plus I don't know if I am getting accurate elapsed CPU time
either. 
	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? Or are most tasks heavily I/O bound but so lightly
CPU-bound that the internal clock for GET-INTERNAL-RUN-TIME hardly ticks?

Thank you in advance. (Please email me.)

John

P.S. I tried both Lucid Common Lisp/Sparc on Sun and Macintosh Common Lisp
(MCL 2.0) and the result is the same.

P.P.S. In the worst case, is there a way to print the msg (not the return
value) of TIME which goes to *TRACE-OUTPUT* to a string (so I can parse teh
string later)?
-- 
Joung-woo John Kim				joungwoo@mensa.usc.edu
Computer Science Dept.
University of Southern California, Los Angeles, CA 90089-0781