From: ············@gmail.com
Subject: high resolution timing info
Date: 
Message-ID: <1171636348.222971.107570@j27g2000cwj.googlegroups.com>
I'd like to implement some fine logging functions, that is with a
precision of at least 1 millisecond.
I found the get-universal-time/get-decoded-time standard functions but
they both miss the millisecond info.

Any idea ?

From: Pascal Bourguignon
Subject: Re: high resolution timing info
Date: 
Message-ID: <87sld6cg08.fsf@thalassa.informatimago.com>
············@gmail.com writes:

> I'd like to implement some fine logging functions, that is with a
> precision of at least 1 millisecond.
> I found the get-universal-time/get-decoded-time standard functions but
> they both miss the millisecond info.

GET-INTERNAL-REAL-TIME and GET-INTERNAL-RUN-TIME
with INTERNAL-TIME-UNITS-PER-SECOND

-- 
__Pascal_Bourguignon__       
http://www.informatimago.com/
From: ············@gmail.com
Subject: Re: high resolution timing info
Date: 
Message-ID: <1171640169.962141.309570@h3g2000cwc.googlegroups.com>
On Feb 16, 3:51 pm, Pascal Bourguignon <····@informatimago.com> wrote:
> ············@gmail.com writes:
> > I'd like to implement some fine logging functions, that is with a
> > precision of at least 1 millisecond.
> > I found the get-universal-time/get-decoded-time standard functions but
> > they both miss the millisecond info.
>
> GET-INTERNAL-REAL-TIME and GET-INTERNAL-RUN-TIME
> with INTERNAL-TIME-UNITS-PER-SECOND
>

Well, no since internal-*-time do not offer access to year+month+day
+hour+min+second informations. And those are so helpfull in log
analysis I can't (imagine to) consider not using them.
From: Pascal Bourguignon
Subject: Re: high resolution timing info
Date: 
Message-ID: <87k5yicclv.fsf@thalassa.informatimago.com>
············@gmail.com writes:

> On Feb 16, 3:51 pm, Pascal Bourguignon <····@informatimago.com> wrote:
>> ············@gmail.com writes:
>> > I'd like to implement some fine logging functions, that is with a
>> > precision of at least 1 millisecond.
>> > I found the get-universal-time/get-decoded-time standard functions but
>> > they both miss the millisecond info.
>>
>> GET-INTERNAL-REAL-TIME and GET-INTERNAL-RUN-TIME
>> with INTERNAL-TIME-UNITS-PER-SECOND
>>
>
> Well, no since internal-*-time do not offer access to year+month+day
> +hour+min+second informations. And those are so helpfull in log
> analysis I can't (imagine to) consider not using them.

You can synchronize both clocks.

(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))))))

;; Then:

(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)))



C/USER[60]> (progn (format t "~19,6F~%" (PRECISE-UNIVERSAL-TIME)) 
                   (sleep 1.35)
                   (format t "~19,6F~%" (PRECISE-UNIVERSAL-TIME)) 
                   (values))
  3380630664.406471
  3380630665.760221


Just remember to use TRUNCATE before calling DECODE-UNIVERSAL-TIME.           

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

Nobody can fix the economy.  Nobody can be trusted with their finger
on the button.  Nobody's perfect.  VOTE FOR NOBODY.
From: John Thingstad
Subject: Re: high resolution timing info
Date: 
Message-ID: <op.tnutolkppqzri1@pandora.upc.no>
On Fri, 16 Feb 2007 17:05:00 +0100, Pascal Bourguignon  
<···@informatimago.com> wrote:

> You can synchronize both clocks.
> (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))))))
> ;; Then:
> (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)))
> C/USER[60]> (progn (format t "~19,6F~%" (PRECISE-UNIVERSAL-TIME))
>                    (sleep 1.35)
>                    (format t "~19,6F~%" (PRECISE-UNIVERSAL-TIME))
>                    (values))
>   3380630664.406471
>   3380630665.760221
> Just remember to use TRUNCATE before calling DECODE-UNIVERSAL-TIME.

Interesting.. Added

(defvar days '("monday" "tuesday" "wednesday" "thursday" "friday"
                         "saturday" "sunday"))

(defun millisec-time ()
   (let ((time (precise-universal-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)
         (format t "time: ~D:~D:~D.~D~%"
                 hour minute second (truncate (* milli-second 1000)))
         (format t "date: ~D/~D-~D~%" date month year)
         (format t "day: ~A daylight-savings: ~A zone: GMT~D~%"
                 (nth day days)
                 (if daylight-p "yes" "no")
                 zone)))))

CL-USER 27 > (millisec-time)
time: 19:22:2.109
date: 16/2-2007
day: friday daylight-savings: no zone: GMT-1
NIL

(Norwegian date format.)

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
From: Pascal Bourguignon
Subject: Re: high resolution timing info
Date: 
Message-ID: <873b56c5l2.fsf@thalassa.informatimago.com>
"John Thingstad" <··············@chello.no> writes:

> (defun millisec-time ()
>   (let ((time (precise-universal-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)
>         (format t "time: ~D:~D:~D.~D~%"
>                 hour minute second (truncate (* milli-second 1000)))

You can write:
                                     (truncate milli-second 1/1000)
or:
                                     (truncate milli-second 0.001)

C/USER[69]> (truncate (nth-value 1 (truncate 123.456)) 1/1000)
456 ;
1.2512207E-6
C/USER[70]> (truncate (nth-value 1 (truncate 123.456)) 0.001)
456 ;
1.2512207E-6

>         (format t "date: ~D/~D-~D~%" date month year)
>         (format t "day: ~A daylight-savings: ~A zone: GMT~D~%"
>                 (nth day days)
>                 (if daylight-p "yes" "no")
>                 zone)))))
>
> CL-USER 27 > (millisec-time)
> time: 19:22:2.109
> date: 16/2-2007
> day: friday daylight-savings: no zone: GMT-1
> NIL
>
> (Norwegian date format.)
>
> -- 
> Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

PLEASE NOTE: Some quantum physics theories suggest that when the
consumer is not directly observing this product, it may cease to
exist or will exist only in a vague and undetermined state.
From: ············@gmail.com
Subject: Re: high resolution timing info
Date: 
Message-ID: <1171749401.066271.310250@j27g2000cwj.googlegroups.com>
On Feb 16, 5:05 pm, Pascal Bourguignon <····@informatimago.com> wrote:
> ············@gmail.com writes:
> > On Feb 16, 3:51 pm, Pascal Bourguignon <····@informatimago.com> wrote:
> >> ············@gmail.com writes:
> >> > I'd like to implement some fine logging functions, that is with a
> >> > precision of at least 1 millisecond.
> >> > I found the get-universal-time/get-decoded-time standard functions but
> >> > they both miss the millisecond info.
>
> >> GET-INTERNAL-REAL-TIME and GET-INTERNAL-RUN-TIME
> >> with INTERNAL-TIME-UNITS-PER-SECOND
>
> > Well, no since internal-*-time do not offer access to year+month+day
> > +hour+min+second informations. And those are so helpfull in log
> > analysis I can't (imagine to) consider not using them.
>
> You can synchronize both clocks.
>
> (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))))))
>
> ;; Then:
>
> (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)))
>
> C/USER[60]> (progn (format t "~19,6F~%" (PRECISE-UNIVERSAL-TIME))
>                    (sleep 1.35)
>                    (format t "~19,6F~%" (PRECISE-UNIVERSAL-TIME))
>                    (values))
>   3380630664.406471
>   3380630665.760221
>
> Just remember to use TRUNCATE before calling DECODE-UNIVERSAL-TIME.
>

Well ... thanks. Time for me to learn beyond the simple loop
flavour ;)