get-internal-run-time
get-internal-run-time Function
Syntax:
get-internal-run-time ⟨no arguments⟩ → internal-time
Arguments and Values:
internal-time—a non-negative integer .
Description:
Returns as an integer the current run time in internal time units. The precise meaning of this quantity is implementation-defined; it may measure real time, run time, CPU cycles, or some other quantity. The intent is that the difference between the values of two calls to this function be the amount of time between the two calls during which computational effort was expended on behalf of the executing program.
Affected By:
The implementation, the time of day (i.e., the passage of time).
See Also:
internal-time-units-per-secondNotes:
Depending on the implementation, paging time and garbage collection time might be included in this measurement. Also, in a multitasking environment, it might not be possible to show the time for just the running process, so in some implementations, time taken by other processes during the same time interval might be included in this measurement as well.
Expanded Reference: get-internal-run-time
Measuring CPU time
get-internal-run-time returns the CPU time used by the Lisp process, in internal time units. This excludes time spent waiting (sleeping, I/O, etc.).
(let ((start (get-internal-run-time)))
(loop for i from 1 to 1000000 sum i)
(let ((elapsed (- (get-internal-run-time) start)))
(>= elapsed 0)))
=> T
Converting to seconds
Divide by internal-time-units-per-second to get seconds.
(let ((start (get-internal-run-time)))
(dotimes (i 1000000) (sqrt (float i)))
(numberp (float (/ (- (get-internal-run-time) start)
internal-time-units-per-second))))
;; => T
Difference from get-internal-real-time
get-internal-real-time measures wall-clock time, while get-internal-run-time measures CPU time. Sleep time increases real time but not run time.
(let ((real-start (get-internal-real-time))
(run-start (get-internal-run-time)))
(sleep 0.5)
(let ((real-elapsed (/ (- (get-internal-real-time) real-start)
(float internal-time-units-per-second)))
(run-elapsed (/ (- (get-internal-run-time) run-start)
(float internal-time-units-per-second))))
(> real-elapsed run-elapsed)))
=> T