chronos: A high-performance time library

[ bsd3, data, development, library, parsing, time ] [ Propose Tags ] [ Report a vulnerability ]

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.


[Skip to Readme]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0, 0.2.0, 0.3, 0.4, 1.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5, 1.0.6, 1.0.7, 1.0.8, 1.0.9, 1.1, 1.1.1, 1.1.2, 1.1.3, 1.1.4, 1.1.5, 1.1.5.1, 1.1.6.0, 1.1.6.1
Change log CHANGELOG.md
Dependencies aeson (>=1.1 && <2.3), attoparsec (>=0.13 && <0.15), base (>=4.14 && <4.20), bytebuild (>=0.3.14 && <0.4), byteslice (>=0.2.5.2 && <0.3), bytesmith (>=0.3.7 && <0.4), bytestring (>=0.10 && <0.13), deepseq (>=1.4.4.0), hashable (>=1.2 && <1.5), natural-arithmetic (>=0.1.2 && <0.3), primitive (>=0.6.4 && <0.10), text (>=1.2 && <1.3 || >=2.0 && <2.2), text-short (>=0.1.3 && <0.2), torsor (>=0.1 && <0.2), vector (>=0.11 && <0.14), Win32 (>=2.2 && <2.14) [details]
Tested with ghc ==9.4.8 || ==9.6.3 || ==9.8.1
License BSD-3-Clause
Copyright 2016 Andrew Martin
Author Andrew Martin
Maintainer amartin@layer3com.com, chessai1996@gmail.com
Category Data, Time, Parsing, Development
Home page https://github.com/byteverse/chronos
Bug tracker https://github.com/byteverse/chronos/issues
Source repo head: git clone git://github.com/byteverse/chronos.git
Uploaded by l3c_amartin at 2024-02-15T18:25:06Z
Distributions LTSHaskell:1.1.6.1, NixOS:1.1.6.1, Stackage:1.1.6.1
Reverse Dependencies 26 direct, 29 indirect [details]
Downloads 14392 total (90 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2024-02-15 [all 1 reports]

Readme for chronos-1.1.6.1

[back to package description]

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 name Time
Time.parseTimeM 9.679 μs
Thyme.parseTime 1.743 μs
Thyme.timeParser 1.113 μs
Chronos.parserUtf8_YmdHMS 301.4 ns
Chronos.zeptoUtf8_YmdHMS 173.6 ns

Pretty-printing

Benchmark name Time
dmy/Time.formatTime 4.404 μs
dmy/Thyme.formatTime 663.0 ns
dmy/Chronos.builder_Dmy 340.9 ns
HMS/Time.formatTime 1.987 μs
HMS/Thyme.formatTime 879.1 ns
HMS/Chronos.builder_HMS 481.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.