time
time Macro
Syntax:
time form → {result}*
Arguments and Values:
form—a form; evaluated as described below.
results—the values returned by the form.
Description:
time evaluates form in the current environment (lexical and dynamic). A call to time can be compiled.
time prints various timing data and other information to trace output. The nature and format of the printed information is implementation-defined. Implementations are encouraged to provide such information as elapsed real time, machine run time, and storage management statistics.
Affected By:
The accuracy of the results depends, among other things, on the accuracy of the corresponding functions provided by the underlying operating system.
The magnitude of the results may depend on the hardware, the operating system, the lisp implementation, and the state of the global environment. Some specific issues which frequently affect the outcome are hardware speed, nature of the scheduler (if any), number of competing processes (if any), system paging, whether the call is interpreted or compiled, whether functions called are compiled, the kind of garbage collector involved and whether it runs, whether internal data structures (e.g., hash tables) are implicitly reorganized, etc.
See Also:
get-internal-real-time, get-internal-run-time
Notes:
In general, these timings are not guaranteed to be reliable enough for marketing comparisons. Their value is primarily heuristic, for tuning purposes.
For useful background information on the complicated issues involved in interpreting timing results, see Performance and Evaluation of Lisp Programs.
Expanded Reference: time
Measuring execution time
time evaluates a form, prints timing and resource usage information, and returns the form's values.
(time (loop for i from 1 to 1000000 sum i))
; Evaluation took:
; 0.003 seconds of real time
; 0.003 seconds of total run time
; ...
=> 500000500000 ; the actual return value
Timing a function call
(time (sleep 0.1))
; Evaluation took:
; 0.100 seconds of real time
; ...
=> NIL
The return value passes through
time returns exactly the same values as the form being timed.
(multiple-value-bind (q r) (time (floor 17 5))
(list q r))
; Prints timing information
=> (3 2)
Timing a computation
The printed information is implementation-dependent but typically includes real time, run time, and memory allocation.
(listp (time (make-list 100000)))
;; prints timing information (implementation-dependent)
;; => T