10 releases (5 breaking)

✓ Uses Rust 2018 edition

new 0.6.0 Jul 6, 2020
0.5.3-alpha.1 May 26, 2020
0.4.1 Feb 25, 2020
0.3.1 Jun 2, 2019
0.2.0 Mar 10, 2019

#1 in #timing

Download history 1577/week @ 2020-03-16 1791/week @ 2020-03-23 2715/week @ 2020-03-30 2452/week @ 2020-04-06 4014/week @ 2020-04-13 3468/week @ 2020-04-20 4650/week @ 2020-04-27 3448/week @ 2020-05-04 5102/week @ 2020-05-11 3266/week @ 2020-05-18 3523/week @ 2020-05-25 4894/week @ 2020-06-01 6626/week @ 2020-06-08 8794/week @ 2020-06-15 5542/week @ 2020-06-22 3481/week @ 2020-06-29

19,832 downloads per month
Used in 20 crates (8 directly)

MIT license

52KB
792 lines

quanta

conduct-badge travis-badge downloads-badge release-badge docs-badge libraries-io-badge cargo-make-badge license-badge

quanta is a high-speed timing library, useful for getting the current time very quickly.

code of conduct

NOTE: All conversations and contributions to this project shall adhere to the Code of Conduct.

usage

The API documentation of this library can be found at docs.rs/quanta.

general features

  • monotonic time in nanoseconds or raw cycles
  • extremely low overhead where possible
  • optimized for instruction-level accuracy in measurements
  • mockable!
  • cross-platform!
  • fun, science-y name!

platform / architecture support

For platforms, we have tier 1 support for Linux, Windows, and macOS/iOS. Platforms such as Solaris or various BSDs has tier 2.5 support: quanta should work on them by virtue of depending on libc, but we don't test or build on these platforms as all.

Architecture-wise, x86/x86-64 and SSE2 are required for the optimized TSC codepath. This is handled transparently via compile-time target features, so you must build with the appropriate compiler flags to specify the CPU features where your binary will run, as runtime detection is not supported.

performance

Accessing the TSC on a modern x86 processor has an extremely low overhead of roughly ~11ns, and quanta provides the thinnest possible layer over this. Using the native time facilities, such as clock_gettime(CLOCK_MONOTONIC) on Linux, you may expect to see closer to 17-18ns of overhead.

Measurements have not been taken for non-x86-based architectures/platforms.

why use this over stdlib or clocksource?

The performance alone is enough to choose this over the stdlib timing facilities if you're doing performance-critical work or need high-accuracy point-in-time measurements, which Instant is just not suitable for.

When compared to clocksource, though, we have a few extra features that can make the difference:

  • Clock can be mocked, allowing you to easily control the passage of time in your tests
  • Clock provides start and end as replacements for raw, which are optimized for instruction-level accuracy, avoiding instruction reordering that might taint measurements

license

quanta is licensed under the MIT license. (LICENSE or http://opensource.org/licenses/MIT)

Dependencies

~240–720KB
~15K SLoC