cl-trivial-clock

2024-10-12

Common Lisp library to get accurate wall-clock times on multiple platforms

Upstream URL

github.com/ak-coram/cl-trivial-clock

Author

Ákos Kiss <ak@coram.pub>

License

MIT License
README

1cl-trivial-clock

Build Status

Common Lisp library to get accurate wall-clock times on multiple platforms

1.1Overview

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)

1.2Installation

cl-trivial-clock can be installed via Quicklisp 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)

1.3Usage

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)

1.3.1Running tests

  • Load the tests via Quicklisp:
  (ql:quickload :trivial-clock/test)
  ;; Using ASDF:
  (asdf:test-system :trivial-clock)
  ;; Using FiveAM directly:
  (fiveam:run! :trivial-clock)

1.4Legal

Dependencies (2)

  • cffi
  • fiveam

Dependents (1)

  • GitHub
  • Quicklisp