MyNixOS website logo
Description

A high-performance time library.

Chronos is a performance-oriented time library for Haskell, with a straightforward API. The main differences between this and the time library are: * Chronos uses machine integers where possible. This means that time-related arithmetic should be faster, with the drawback that the types are incapable of representing times that are very far in the future or the past (because Chronos provides nanosecond, rather than picosecond, resolution). For most users, this is not a hindrance. * Chronos provides ToJSON/FromJSON instances for serialisation. * Chronos provides Unbox instances for working with unboxed vectors. * Chronos provides Prim instances for working with byte arrays/primitive arrays. * Chronos uses normal non-overloaded haskell functions for encoding and decoding time. It provides attoparsec parsers for both Text and ByteString. Additionally, Chronos provides functions for encoding time to Text or ByteString. The http://hackage.haskell.org/package/time time> library accomplishes these with the Data.Time.Format module, which uses UNIX-style datetime format strings. The approach taken by Chronos is faster and catches more mistakes at compile time, at the cost of being less expressive.

Chronos

Chronos is a performance-oriented time library for Haskell, with a straightforward API. The main differences between this and the time library are:

  • Chronos uses machine integers where possible. This means that time-related arithmetic should be faster, with the drawback that the types are incapable of representing times that are very far in the future or the past (because Chronos provides nanosecond, rather than picosecond, resolution). For most users, this is not a hindrance and the tradeoff is worthwhile.
  • Chronos provides 'ToJSON'/'FromJSON' instances for serialisation.
  • Chronos provides 'Unbox' instances for working with unboxed vectors.
  • Chronos provides 'Prim' instances for working with byte arrays/primitive arrays.
  • Chronos uses normal non-overloaded haskell functions for encoding and decoding time. It provides attoparsec parsers for both 'Text' and 'ByteString'. Additionally, Chronos provides functions for encoding time to 'Text' or 'ByteString'. The time library accomplishes these with the Data.Time.Format module, which uses UNIX-style datetime format strings. The approach taken by Chronos is faster and catches more mistakes at compile time, at the cost of being less expressive.

Jacob Stanley has written a blog post comparing the features and performance of time, thyme, and chronos. It has a good bulleted breakdown of why you may want to use each library along with some benchmarks.

Benchmarks

Benchmarks of chronos against time and thyme.

Parsing

Benchmark nameTime
Time.parseTimeM9.679 μs
Thyme.parseTime1.743 μs
Thyme.timeParser1.113 μs
Chronos.parserUtf8_YmdHMS301.4 ns
Chronos.zeptoUtf8_YmdHMS173.6 ns

Pretty-printing

Benchmark nameTime
dmy/Time.formatTime4.404 μs
dmy/Thyme.formatTime663.0 ns
dmy/Chronos.builder_Dmy340.9 ns
HMS/Time.formatTime1.987 μs
HMS/Thyme.formatTime879.1 ns
HMS/Chronos.builder_HMS481.3 ns

Doctest

Doctest used to be provided as a test suite, but doctest-0.20 and higher do not require this to be run. To run the doctests, make sure you have doctest on your path (i.e. run cabal install doctest), and then run:

cabal build
cabal repl --build-depends=QuickCheck --with-ghc=doctest --repl-options='-fno-warn-orphans'

Doctest now runs as part of CI.

Metadata

Version

1.1.6.1

Platforms (77)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows