Crate fastant

Source
Expand description

A drop-in replacement for std::time::Instant that measures time with high performance and high accuracy powered by Time Stamp Counter (TSC).

§Example

let start = fastant::Instant::now();
let duration: std::time::Duration = start.elapsed();

§Platform Support

Currently, only the Linux on x86 or x86_64 is backed by Time Stamp Counter (TSC). On other platforms, fastant falls back to coarse time.

§Calibration

Time Stamp Counter (TSC) doesn’t necessarily tick in constant speed and even doesn’t synchronize across CPU cores. The calibration detects the TSC deviation and calculates the correction factors with the assistance of a source wall clock. Once the deviation is beyond a crazy threshold, the calibration will fail, and then we will fall back to coarse time.

This calibration is stored globally and reused. In order to start the calibration before any call to fastant as to make sure that the time spent on fastant is constant, we link the calibration into application’s initialization linker section, so it’ll get executed once the process starts.

See also the Instant type.

Structs§

Anchor
An anchor which can be used to convert internal clocking counter into system timestamp.
Atomicatomic and target_has_atomic="64"
Atomic variant of Instant.
Instant
A measurement of a monotonically non-decreasing clock. Similar to std::time::Instant but is faster and more accurate if TSC is available.

Functions§

is_tsc_available
Return true if the current platform supports Time Stamp Counter (TSC), and the calibration has succeeded.