Lisp HUG Maillist Archive

Timing functions

Hi,

Is there anyway to time functions with a higher resolution than
what the time macro gives ? Is it possible to report microseconds
rather than milliseconds ?

Best regards,

--
Fabrice

Re: Timing functions

on osx :

(mach_absolute_time) gives you an absolute time that is CPU dependent (microseconds or even better).

You can even wait for a very precise delay with (mach_wait_until deadline) where 'deadline' is a timestamp in the same time unit.

foreign functions needed (in framework : "/System/Library/Frameworks/System.framework/System") : 

(define-c-typedef Uint32 (:unsigned :long))
(define-c-typedef Uint64 (:unsigned :long :long))
(define-c-typedef Sint32 (:signed :long))

(define-c-struct mach_timebase_info
 (num UInt32)
 (den UInt32))

(define-foreign-function (mach_absolute_time "mach_absolute_time") ()
 :module :system
 :result-type Uint64)

(define-foreign-function (mach_timebase_info "mach_timebase_info") ((info (:ptr mach_timebase_info)))
 :module :system
 :result-type Sint32)

(define-foreign-function (mach_wait_until "mach_wait_until") ((deadline UInt64))
 :module :system
 :result-type Sint32)

You'll find more info here : http://developer.apple.com/library/mac/#qa/qa1398/_index.html

Another possibility (at a higher level) is to work with the time functions of coreAudio.

Best regards

Denis

------------------------------------------------
Denis Pousseur
70 rue de Wansijn
1180 Bruxelles
+ 32 2 219 31 09
http://www.denispousseur.com
------------------------------------------------

Le 22 mars 2013 à 12:37, Fabrice Popineau <fabrice.popineau@supelec.fr> a écrit :

Hi,

Is there anyway to time functions with a higher resolution than
what the time macro gives ? Is it possible to report microseconds
rather than milliseconds ?

Best regards,

--
Fabrice

Updated at: 2020-12-10 08:35 UTC