;;; WARNING: UNTESTED! ;;; Uses the POSIX clock_gettime C function to return the current ;;; nanoseconds. Suitable only for Linux and BSD. Not portable to ;;; Windows or Mac. (module nanoseconds (current-nanoseconds) (import chicken scheme foreign) (foreign-declare "#include ") ;; Return the current nanoseconds, or -1 if an error occurs. (define current-nanoseconds (foreign-lambda* long () "struct timespec ts;" "int success = clock_gettime(CLOCK_REALTIME, &ts);" "if (-1 == success) {" " C_return(-1);" "} else {" " C_return(ts.tv_nsec);" "}"))) (import nanoseconds) (print (current-nanoseconds))