Skip to content

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

License

Notifications You must be signed in to change notification settings

ak-coram/cl-trivial-clock

Repository files navigation

cl-trivial-clock

Build Status

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

Overview

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)

Installation

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.

Usage

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)

Running 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)

Legal

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published