(foreign-declare "#include ") (define get-microsecs (foreign-lambda* double () "uint64_t time = clock_gettime_nsec_np( CLOCK_UPTIME_RAW );" "if( 0 == time ) return( -1.0 );" "return( ((double) time) / 1e3 );")) #| ;pre-Sierra 10.12 (foreign-declare "#include ") (define get-microsecs) (let ((%factor (the (or float boolean) #f))) ; (define %calc-time (foreign-lambda* double () "uint64_t time = mach_absolute_time();" "return( ((double) time) / 1e3 );")) ; (define %calc-factor (foreign-lambda* double () "mach_timebase_info_data_t info;" "mach_timebase_info( &info );" "return( ((double) info.numer) / ((double) info.denom) );")) ; (set! get-microsecs (lambda () (* (%calc-time) %factor))) ; ;we immediatly determine the factor ;it should not change as long as the machine runs (set! %factor (%calc-factor)) (unless (positive? %factor) (error 'get-microsecs "cannot determine scale factor" %factor) ) ) |#