Common Lisp library to get accurate wall-clock times on multiple platforms
CL:GET-UNIVERSAL-TIME is limited to returning whole seconds, but some platforms can provide more accurate clocks. This library aims to wrap platform-specific system calls for this purpose and fall back on CL:GET-UNIVERSAL-TIME on any unsupported platform.
Currently the clock_gettime call is used (with CLOCK_REALTIME) on all Unix systems and GetSystemTimePreciseAsFileTime on Windows, except for Windows versions below version 8 where GetSystemTimeAsFileTime is used.
The following software combinations are tested via GitHub actions on x86-64:
- SBCL (Linux, Windows, macOS, OpenBSD, FreeBSD, DragonflyBSD)
- CCL (Linux)
- ECL (Linux, macOS, OpenBSD, FreeBSD)
cl-trivial-clock can be installed via Quicklisp:
(ql:quickload :trivial-clock)
The latest version is available from the Ultralisp distribution:
;; Install the ultralisp distribution if you don't have it already
(ql-dist:install-dist "http://dist.ultralisp.org/" :prompt nil)
;; Load cl-trivial-clock
(ql:quickload :trivial-clock)
Alternatively you can also rely on ocicl.
The function NOW returns the number of seconds since the unix epoch and the number of additional nanoseconds as a second value:
;; Get current wall-clock time:
(trivial-clock:now)
;; => 1688533183 (31 bits, #x64A4F8BF)
;; 529460903 (29 bits, #x1F8EEEA7)
- Load the tests via Quicklisp:
(ql:quickload :trivial-clock/test)
;; Using ASDF:
(asdf:test-system :trivial-clock)
;; Using FiveAM directly:
(fiveam:run! :trivial-clock)
- Released under the MIT License
- Developer Certificate of Origin
- Source for README photo