Crate clocksource [−] [src]
Alternate timing sources for Rust
Goals
- high-performance
- graceful fallback for stable Rust
Future work
- additional platforms
Usage
Note: You must be on nightly Rust to use the rdtsc feature which
allows access to the high-speed time stamp counter on x86_64
Example
Create a clocksource and read from it
use clocksource::Clocksource; // create a `Clocksource` with rdtsc if on nightly // falls-back to clock_gettime() otherwise let mut clocksource = Clocksource::new(); // we can read the nanoseconds from the clocksource // this adds some conversion overhead let time_0 = clocksource.time(); // we can read the time from the reference clock // this should be a zero-cost abstraction let ref_0 = clocksource.reference(); // we can access the raw value of the counter that // forms the clocksource (eg, the TSC if on nightly) // this is ideal for tight loops let counter_0 = clocksource.counter(); // we can convert the counter value to a time, allowing // separation of timing events and conversion to reference timescale let time_0 = clocksource.convert(counter_0); // we can read the estimated frequency of the counter let frequency = clocksource.frequency(); // we can also estimate the phase error between the // source clock and the reference clock let phase_error = clocksource.phase_error();
Structs
Clocksource |
Enums
Clock |