In lisp, how can I measure and record the time taken to evaluate an expression?

I want to get the results of the time macro call in order to collect several measurements and process them. I tried the locally setf standard output and redirected it to a string, but it did not work with the time macro. This may be wrong, but I tried:

 (with-output-to-string (str) (let ((*standard-output* str)) (time (test-with-size 40)))) 

Questions:

  • Is there a way to capture the output of time ?
  • If not, can I capture the output of the slime-profile-report command?
  • If none of the above works, how can I measure the time spent evaluating an arbitrary expression?

I want to measure the execution time of an algorithm as the input size increases for each input size (from 1 to 100). I will measure many times and keep the average value. Then I want to build the results. The continuity is simple, and I found many ways in Cliki, but how can I collect the results?

I use CLISP and CCL.

EDIT: Paul Nathan pointed out that the time macro outputs to *trace-output* , which is the solution. I would like to get a more pleasant and simple solution, because with this I have to deal with implementation-specific tracing.

+7
source share
1 answer

If you want to capture text, you need to use the correct stream. The ANSI CL standard says TIME prints for trace output.

So this will give you text as a string.

 (with-output-to-string (*trace-output*) (time (sin 40.0))) 

You can also write your own macro using time primitives. See 25.1.4.3 Internal time for numerical data.

+9
source

All Articles