From: Jurn Franken
Subject: Measuring user time.
Date: 
Message-ID: <cs80v8$ork$1@june.cs.uu.nl>
Hello,

I'm trying to measure the user time spent in some code of mine.

The macro "time" prints some detailed information about the system.
For my version of SBCL it does something like this:

Evaluation took:
   		 35.573 seconds of real time
   		 24.47 seconds of user run time
   		 9.93 seconds of system run time
   		 0 page faults and
   		 3705055032 bytes consed.

Ideally, I would like to have the information printed by the macro time 
in some usable form. Maybe it is most clear to just describe the 
behaviour wanted.

for example:
(defun my-time (fun)
    ...
    (values (multiple-value-list (funcall fun))
            real-time
            user-run-time
            system-run-time
            page-faults
            bytes-consed))

This way I can always later on return the original values with:
(eval (push 'values value-list))
   ;;; where value-list is a list with the values
   ;;; of the original function

--- QUESTION ---
Is there a way to get this system info ?

(I already had a look at the Lisp Cookbook "timing" macro but this just 
returns the sum of user-run-time and system-run-time, and the "time" 
macro from time.lisp uses the functions (get-sys-time) and 
(get-system-time) but I don't understand how to call them.)

--- sub question ---
And a more philosophical question;
what is exactly measured with real-time, user-run-time, system-run-time?


Best regards,
Jurn Franken

From: Lars Brinkhoff
Subject: Re: Measuring user time.
Date: 
Message-ID: <85vfa0qsn0.fsf@junk.nocrew.org>
Jurn Franken <···········@gmail.com> writes:
> I'm trying to measure the user time spent in some code of mine.
> for example:
> (defun my-time (fun)
>     ...
>     (values (multiple-value-list (funcall fun))
>             real-time
>             user-run-time
>             system-run-time
>             page-faults
>             bytes-consed))

Maybe something like:

  (defun my-time (fun)
    (let ((real-start (get-internal-real-time))
          (run-start (get-internal-run-time)))
      (values (multiple-value-list (funcall fun)))
              (- (get-internal-real-time) real-start)
              (- (get-internal-run-time) run-start)))

I believe there is no portable way to get information about system
time, page faults, or bytes consed.

> This way I can always later on return the original values with:
> (eval (push 'values value-list))
>    ;;; where value-list is a list with the values
>    ;;; of the original function

Or simpler:

  (values-list value-list)

-- 
Lars Brinkhoff,         Services for Unix, Linux, GCC, HTTP
Brinkhoff Consulting    http://www.brinkhoff.se/
From: Jurn Franken
Subject: Re: Measuring user time.
Date: 
Message-ID: <cs84fa$q2h$1@june.cs.uu.nl>
> Lars Brinkhoff wrote:
> Jurn Franken <···········@gmail.com> writes:
>
> Maybe something like:
> 
>   (defun my-time (fun)
>     (let ((real-start (get-internal-real-time))
>           (run-start (get-internal-run-time)))
>       (values (multiple-value-list (funcall fun)))
>               (- (get-internal-real-time) real-start)
>               (- (get-internal-run-time) run-start)))
>

Thanks, this is essentially the Lisp Cookbook "timing" macro, and at 
least it gets the real-time and run-time.

> I believe there is no portable way to get information about system
> time, page faults, or bytes consed.
> 

Well, there is a function (get-bytes-consed) which works analog to 
(get-internal-run-time)

And also, if I don't know the exact meaning of user-run-time and 
system-run-time whats the use of using them.
(But then again, I like to know what I'm measuring)

> Or simpler:
> 
>   (values-list value-list)
> 

Thanks

Jurn Franken
From: Martin Ginkel
Subject: Re: Measuring user time.
Date: 
Message-ID: <cs8ids$5nf$1@gwdu112.gwdg.de>
Jurn Franken wrote:
> --- QUESTION ---
> Is there a way to get this system info ?

There is no portable way to get *all* the information.
The output of time also differs on implementations.
E.g. ACL separately measures times in app-code and in GC.

> (I already had a look at the Lisp Cookbook "timing" macro but this just 
> returns the sum of user-run-time and system-run-time, and the "time" 
> macro from time.lisp uses the functions (get-sys-time) and 
> (get-system-time) but I don't understand how to call them.)

Hmm: call them before and after your code (singlethread) and substract 
the results.

(let ((s (get-internal-run-time)))
   ;; spend some time computing
   (loop for i from 1 to (expt 2 16) sum i)
   (print (- (get-internal-run-time) s)))

> 
> --- sub question ---
> And a more philosophical question;
> what is exactly measured with real-time, user-run-time, system-run-time?

real-time is the time on your watch from start of computation
to the end, including time, not spent in your lisp process.

user-time is the time, the processor spent working in your lisp
code. (most valuable for profiling)

sys-time is time spent in the operating-system (e.g. for IO, Malloc and 
scheduling) for system-calls by your program. This is measured without 
IO-waiting time in OS.
(in many cases far less user-time)


	HTH
	Martin

-- 
+-[Martin Ginkel]-------------[mailto:mginkel(at)mpi-magdeburg.mpg.de]-+
| MPI Magdeburg, Zi S2.09    Sandtorstr. 1, D-39106 Magdeburg, Germany |
| Simple things should be simple and complex things should be          |
| possible.                                                Alan K.     |
+-[tel/fax: +49 391 6110 482/529]----[http://www.mpi-magdeburg.mpg.de]-+
From: Rahul Jain
Subject: Re: Measuring user time.
Date: 
Message-ID: <87mzv8fz3o.fsf@nyct.net>
Martin Ginkel <·············@epost.de> writes:

> user-time is the time, the processor spent working in your lisp
> code. (most valuable for profiling)
>
> sys-time is time spent in the operating-system (e.g. for IO, Malloc and
> scheduling) for system-calls by your program. This is measured without
> IO-waiting time in OS.
> (in many cases far less user-time)

Depending on how the OS and C library are implemented, user time may be
spent on tasks that are "OS-related" by someone's criteria (in the sense
that as far as a lisp programmer cares, all calls to libc functions are
to access the OS, so they "should" all be put in as system time).

-- 
Rahul Jain
·····@nyct.net
Professional Software Developer, Amateur Quantum Mechanicist