Pergunta

Common Lisp provide a time macro for finding out how long a form takes to execute, and it prints the information to the trace output:

time evaluates form in the current environment (lexical and dynamic). … 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.

For instance:

(time (length (make-array 1000000)))
      Real time: 0.0140014 sec.
      Run time: 0.0 sec.
      Space: 4000008 Bytes
      GC: 1, GC time: 0.0 sec.

Is there a way to collect these parameters and push them step by step into some stack or list and return it from a function?

Foi útil?

Solução

Some things are standard: get-internal-run-time and get-internal-real-time:

(defvar *my-timings* nil)
(let ((run (get-internal-run-time))
      (real (get-internal-real-time)))
  (multiple-value-prog1 (my-code)
    (push (cons (- (get-internal-run-time) run)
                (- (get-internal-real-time) real))
          *my-timings*)))

Others are not (space and GC count), you need to find the implementation-specific versions.

You might also consider using with-timing - it provides progress reports including ETA.

Incidentally, in your code, memory allocation (make-array) dwarfs length (which is slot access for an array).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top