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 platforms, we have tier 1 support for Linux, Windows, and macOS/iOS. Platforms such as Solaris or various BSDs have 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.
Both x86/x86-64 and SSE2 support are checked for at compile-time, so compiler flags must be set correctly. Further checks will happen at runtime to assert that the TSC source itself is stable enough for taking measurements, and if so, will be utilized.
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)