Crates.io | quanta |
lib.rs | quanta |
version | 0.12.3 |
source | src |
created_at | 2019-01-14 12:28:55.369353 |
updated_at | 2024-03-31 17:41:40.287696 |
description | high-speed timing library |
homepage | https://github.com/metrics-rs/quanta |
repository | https://github.com/metrics-rs/quanta |
max_upload_size | |
id | 108498 |
size | 92,080 |
quanta is a high-speed timing library, useful for getting the current time very quickly, as well as manipulating it.
NOTE: All conversations and contributions to this project shall adhere to the Code of Conduct.
The API documentation of this library can be found at docs.rs/quanta.
For most major platforms -- Linux, Windows, and macOS -- with processors made around or after 2008,
you should have no problems using quanta
with full TSC support. quanta
will always fallback to
the included stdlib timing facilities if TSC support is not present. The biggest caveat to this, as
evidenced in the compatibility matrix below, is that we only support the TSC on x86/x86_64 platforms.
Platform | stdlib fallback | TSC support? | CI tests? |
---|---|---|---|
Linux (x86/x86_64) | ✅ | ✅ | ✅ |
Linux (MIPS/ARM) | ✅ | ❌ | ✅ |
Windows (x86/x86_64) | ✅ | ✅ | ✅ |
Windows (ARM) | ✅ | ❌ | ❌ |
macOS (x86/x86_64) | ✅ | ✅ | ✅ |
macOS (ARM) | ✅ | ❌ | ❌ |
iOS (ARM) | ✅ | ❌ | ❌ |
quanta
sits neck-and-neck with native OS time facilities: the cost of Clock::now
is on par
Instant::now
from the stdlib, if not better.
Beyond having a performance edge in specific situations, the ability to use mocked time makes it easier to actually test that your application is doing the right thing when time is involved.
Additionally, and as mentioned in the general features section, quanta
provides a safe/thin
wrapper over accessing the Time Stamp Counter, which allows measuring cycle counts over short
sections of code. This can be relevant/important for accurately measuring performance-critical sections of code.
chrono
:
std::time::SystemTime
: non-monotonic readstime
:
std::time::SystemTime
and std::time::Instant
:
time::Time
/time::PrimitiveDateTime
use SystemTime
: non-monotonic readstime::Instant
uses Instant
: monotonic readsclock
:
std::time::SystemTime
: non-monotonic readsclocksource
:
asm!
macro + feature flag to enable TSCpausable_clock
:
std::time::Instant
: monotonic readsquanta is licensed under the MIT license. (LICENSE or http://opensource.org/licenses/MIT)