how to find CPU time used by each call when inside a loop?

198 views Asked by At

I am learning Maxima, but having hard time finding how to obtain the cpu time used in call to integrate, when inside a loop construct.

The problem is that the function time(%o1) gives the CPU time used to compute line %o1.

But inside a loop, the whole loop is taken as one operation. So I can't use time() to time single call.

Here is an example

   lst:[sin(x),cos(x)];
   for i thru length(lst) do
   (
   result :  integrate( lst[i],x)
   );

I want to find the cpu time used for each call to integrate, not the cpu time used for the whole loop. Adding showtime: true$ does not really help. I need to obtain the CPU time used for each call, and save the value to a variable.

Is there a way in Maxima to find CPU time used by each call to integrate in the above loop?

Using wxMaxima 15.04.0, windows 7. Maxima version: 5.36.1 Lisp: SBCL 1.2.7

I was looking for something like Mathematica's AbsoluteTiming function.

2

There are 2 answers

0
Robert Dodier On BEST ANSWER

Perhaps the function you need is elapsed_real_time.

EDIT: you would use it like this:

for i ...
  do block ([t0, t1],
            t0 : elapsed_real_time (),
            integrate (...),
            t1 : elapsed_real_time (),
            time[i] : t1 - t0);
0
Richard Fateman On

instead of elapsed real time, which on my GCL maxima seems to return absolute real time in seconds, try the lisp function

GET-INTERNAL-RUN-TIME

which you can call from the Maxima command line by

?get-internal-run-time();

This should return run time on any common lisp system. In GCL, in units of 100 per second.