All Manuals > LispWorks® User Guide and Reference Manual > 33 The COMMON-LISP Package

time Macro

Summary

Determines the execution time of a form in the current environment.

Package

common-lisp

Signature

time form => values

Arguments
form
A form to be evaluated.
Values
values
The values returned by evaluation of form.
Description

The macro time can be used to determine execution times. The macro evaluates the form form and returns its values values. time also prints some timing and size data: user time, system time, elapsed time, and the total amount of heap space allocated in executing the form (in bytes).

The user time printed is the time used by LispWorks or any code that it calls in a dynamic library.

The system time printed is the time used in the operating system kernel when it is doing work on behalf of the LispWorks process.

The elapsed time printed is the time you could in principle measure with a stopwatch.

If LispWorks is 100% busy throughout the execution of the code, then user time + system time ~= elapsed time.

Each of the times is printed as:

The timing and size data covers all stack groups, not just the one that invokes time.

Notes
  1. Note that time itself uses a small, constant amount of heap space.
  2. time measures all threads, so to test accurately for consing in code you need to do:
    (sys:with-other-threads-disabled (time code))
    

    This is particularly important when using the LispWorks IDE. Do not use with-other-threads-disabled in your application code.

Examples
CL-USER 7 >  (time (loop for i below 3000000
                         sum (sqrt i)))
Timing the evaluation of (LOOP FOR I BELOW 3000000 SUM (SQRT I))
 
User time    =  0:01:04.187
System time  =        0.062
Elapsed time =  0:01:07.297
Allocation   = 4932022956 bytes
0 Page faults
Calls to %EVAL    72000048
3.4606518E9
See also

time in the Common Lisp HyperSpec
extended-time
with-other-threads-disabled
with-unique-names
11.2 Guidance for control of the memory management system


LispWorks® User Guide and Reference Manual - 01 Dec 2021 19:30:30