From: Chris Schumacher
Subject: Saving time.
Date: 
Message-ID: <Xns98F9247CF2C3Dkensuhotmailcom@216.170.153.147>
Is there any way to set the information you get from the "time" function to 
a variable. I assumed it was a list, so used setf, but it appears all it 
actually returns is the output of the timed function. The timing 
information is lost.
Thanks,


    	    	    	    	    	-==Kensu==-

From: Lars Rune Nøstdal
Subject: Re: Saving time.
Date: 
Message-ID: <45ff9f19$0$29074$c83e3ef6@nn1-read.tele2.net>
On Tue, 20 Mar 2007 08:35:12 +0000, Chris Schumacher wrote:

> Is there any way to set the information you get from the "time" function to 
> a variable. I assumed it was a list, so used setf, but it appears all it 
> actually returns is the output of the timed function. The timing 
> information is lost.
> Thanks,
> 
> 
>     	    	    	    	    	-==Kensu==-


cl-user> (let ((time (with-output-to-string (*trace-output*)
                       (time (dotimes (i 10000)
                               'do 'something 'here)))))
           `(parse ,time here))
                   
(parse "Evaluation took:
  0.0 seconds of real time
  0.0 seconds of user run time
  0.0 seconds of system run time
  0 calls to %EVAL
  0 page faults and
  0 bytes consed.
"
 here)

-- 
Lars Rune Nøstdal
http://nostdal.org/
From: Pascal Bourguignon
Subject: Re: Saving time.
Date: 
Message-ID: <87vegwz48o.fsf@voyager.informatimago.com>
Chris Schumacher <·······@hotmail.com> writes:

> Is there any way to set the information you get from the "time" function to 
> a variable. I assumed it was a list, so used setf, but it appears all it 
> actually returns is the output of the timed function. The timing 
> information is lost.

No. TIME, and most of the other functions in that CLHS chapter are not
designed to be used from programs, but interactively, as crude
debugging tools.


But you can implement your own, using get-internal-run-time or get-internal-real-time.
For example:

(defun internal-time (thunk)
  (let ((start   (get-internal-run-time))
        (results (multiple-value-list (funcall thunk)))
        (end     (get-internal-run-time)))
     (values (/ (- end start) INTERNAL-TIME-UNITS-PER-SECOND)
             results)))

(internal-time (lambda () 
                 (loop :repeat 3500 :with i = 0 :do (incf i)
                       :finally (return (values "I had fun." 
                                                '(how long was it?))))))
--> 3999/1000000 ;
    ("I had fun." (HOW LONG WAS IT?))



-- 
__Pascal Bourguignon__
http://www.informatimago.com
http://pjb.ogamita.org
From: John Thingstad
Subject: Re: Saving time.
Date: 
Message-ID: <op.tphcennlpqzri1@pandora.upc.no>
On Tue, 20 Mar 2007 09:35:12 +0100, Chris Schumacher <·······@hotmail.com>  
wrote:

> Is there any way to set the information you get from the "time" function  
> to
> a variable. I assumed it was a list, so used setf, but it appears all it
> actually returns is the output of the timed function. The timing
> information is lost.
> Thanks,
>
>
>     	    	    	    	    	-==Kensu=

You mean like this?

(multiple-value-bind (second minute hour date month year day daylight-p  
zone)
       (decode-universal-time (get-universal-time))

The time in get-univeral-time is a integer representing seconds since  
1/1-1900 00:00:00 UTC.
There is no "time" function.

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
From: John Thingstad
Subject: Re: Saving time.
Date: 
Message-ID: <op.tphcypztpqzri1@pandora.upc.no>
On Tue, 20 Mar 2007 09:55:25 +0100, John Thingstad  
<··············@chello.no> wrote:

> On Tue, 20 Mar 2007 09:35:12 +0100, Chris Schumacher  
> <·······@hotmail.com> wrote:
>
>> Is there any way to set the information you get from the "time"  
>> function to
>> a variable. I assumed it was a list, so used setf, but it appears all it
>> actually returns is the output of the timed function. The timing
>> information is lost.
>> Thanks,
>>
>>
>>     	    	    	    	    	-==Kensu=
>
> You mean like this?
>
> (multiple-value-bind (second minute hour date month year day daylight-p  
> zone)
>        (decode-universal-time (get-universal-time))
>
> The time in get-univeral-time is a integer representing seconds since  
> 1/1-1900 00:00:00 UTC.
> There is no "time" function.
>

Duh! (time (operation)).. To early for me.
Here's something to play with (from http://cl-php-date.sf.net)

;; precise-universal-time uses code provided by Pascal Bourgignon
;; on comp.lang.lisp

(defvar *internal-real-time-sync*
   (progn
     (loop with coarse-time = (get-universal-time)
           while (= coarse-time (get-universal-time)))
     (loop
       with coarse-time = (get-universal-time)
       for current-time = (get-universal-time)
       while (= coarse-time current-time)
       finally (return (cons (get-universal-time)
                             (get-internal-real-time))))))

(defun precise-universal-time ()
   (+ (coerce (car *internal-real-time-sync*) 'double-float)
      (/ (- (get-internal-real-time) (cdr *internal-real-time-sync*))
         internal-time-units-per-second)))

(defun decode-precise-universal-time (time)
   (multiple-value-bind (second milli-second) (truncate time)
     (multiple-value-bind
         (second minute hour date month year day daylight-p zone)
         (decode-universal-time second)
       (values  (truncate milli-second 1/1000) second minute hour
               date month year day daylight-p zone))))

(defun encode-precise-universal-time (milli-second second minute hour
                                            date month year zone)
   (let ((seconds  (encode-universal-time second minute hour
                                          date month year zone)))
     (+ seconds (coerce (/ milli-second 1000) 'double-float))))

and something like

(defun (my-time operation &rest args)
   (let* ((start (precise-universal-time))
          (result (funcall operation args))
	 (end (precise-universal-time))
      (decode-precise-universal-time (- end start))))


-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
From: Pascal Bourguignon
Subject: Re: Saving time.
Date: 
Message-ID: <87r6rjzuz3.fsf@voyager.informatimago.com>
"John Thingstad" <··············@chello.no> writes:

> On Tue, 20 Mar 2007 09:55:25 +0100, John Thingstad
> <··············@chello.no> wrote:
>> There is no "time" function.
>>
>
> Duh! (time (operation)).. To early for me.
> Here's something to play with (from http://cl-php-date.sf.net)

Well not su Duh, it's a macro ;-)

-- 
__Pascal Bourguignon__
http://www.informatimago.com
http://pjb.ogamita.org
From: Alex Mizrahi
Subject: Re: Saving time.
Date: 
Message-ID: <45ffa1eb$0$90269$14726298@news.sunsite.dk>
(message (Hello 'Chris)
(you :wrote  :on '(Tue, 20 Mar 2007 08:35:12 GMT))
(

 CS> Is there any way to set the information you get from the "time"
 CS> function to a variable. I assumed it was a list, so used setf, but it
 CS> appears all it actually returns is the output of the timed function.
 CS> The timing information is lost.

"time prints various timing data and other information to trace output."

so only way to store it is to capture trace output:

CL-USER> (defparameter *time-outs*
    (with-output-to-string (*trace-output*)
      (time
       (loop for i from 0 to 100
      collect (* i i)))))
*TIME-OUTS*
CL-USER> *time-outs*
"0.031 seconds real time

2918 cons cells

"

 you can then read it, but format is implementation-dependant.

there are also other profiling tools for some implementations. you can check 
SLIME/SWANK -- it's backend provides bindings to profilers for different 
implementations, and there is some programmatic access to it.

TIME cannot return any values because it can be used inside expression, you 
can insert it into any expression without breaking it:

(setf *param* (+ 123 (factorial 4556)))

(setf *param* (+ 123 (time (factorial 4556))))


)
(With-best-regards '(Alex Mizrahi) :aka 'killer_storm)
"�� ���� ������� �����") 
From: Takehiko Abe
Subject: Re: Saving time.
Date: 
Message-ID: <keke-36DF01.17594520032007@nnrp.gol.com>
Chris Schumacher:

> Is there any way to set the information you get from the "time" function to 
> a variable. I assumed it was a list, so used setf, but it appears all it 
> actually returns is the output of the timed function. The timing 
> information is lost.

From the HyperSpec:

  "time prints various timing data and other information to trace
   output."

So, you can bind *trace-output* in order to capture the info. e.g.

(with-output-to-string (*trace-output*)
  (time (foo args)))

--> string
From: Ken Tilton
Subject: Re: Saving time.
Date: 
Message-ID: <BhjNh.697$Px4.433@newsfe12.lga>
I had good luck with my Lisp (ACL) by macroexpanding time and 
discovering the unexported function called and then calling that and 
figuring out how the values returned mapped onto the TIME report. That 
then let me do all sorts of groovy things.

hth.kt

Chris Schumacher wrote:
> Is there any way to set the information you get from the "time" function to 
> a variable. I assumed it was a list, so used setf, but it appears all it 
> actually returns is the output of the timed function. The timing 
> information is lost.
> Thanks,
> 
> 
>     	    	    	    	    	-==Kensu==-

-- 

"As long as algebra is taught in school,
there will be prayer in school." - Cokie Roberts

"Stand firm in your refusal to remain conscious during algebra."
    - Fran Lebowitz

"I'm an algebra liar. I figure two good lies make a positive."
    - Tim Allen

"Algebra is the metaphysics of arithmetic." - John Ray

http://www.theoryyalgebra.com/
From: Ken Tilton
Subject: Re: Saving time.
Date: 
Message-ID: <BfkNh.71$175.39@newsfe12.lga>
Ken Tilton wrote:
> I had good luck with my Lisp (ACL) by macroexpanding time 

(EXCL::TIME-A-FUNCALL #'EXCL::TIME-REPORT #'(LAMBDA NIL (PROGN)))

time-report args are: tgcu tgcs to ts tr scons sother static

ergo I can supply a diff func to time-a-funcall that takes the same args 
and yadda yadda yadda....

hth.kzo

-- 

"Algebra is the metaphysics of arithmetic." - John Ray

http://www.theoryyalgebra.com/