[][src]Crate quanta

High-speed timing facility.

quanta provides a generalized interface to the Time Stamp Counter (TSC) present on modern x86 CPUs, allowing users to measure code section very precisely and with very low overhead.

Design

Internally, two clocks are used — a reference and a source — to provide high-speed access to timing values, while allowing for conversion back to a reference timescale that matches the underlying system.

Calibration between the reference and source happens at initialization time of Clock.

Platform support

quanta supports using the native high-speed timing facilities on the following platforms:

TSC support

Accessing the TSC requires being on the x86/x86_64 architecture, with access to SSE2. If this condition is not met, quanta will compile to use the native OS timing facilities.

Generally speaking, most modern operating systems will already be attempting to use the TSC on your behalf, along with switching to another clocksource if they determine that the TSC is unstable or providing unsuitable speed/accuracy. The primary reason to use TSC directly is that calling it from userspace is measurably faster — although the "slower" methods are still on the order of of tens of nanoseconds — and can be useful for timing operations which themselves are extremely fast.

If your operations run in the hundreds of nanoseconds or less range, or you're measuring in a tight loop, using the TSC could help you avoid the normal overhead which would otherwise contribute to a large chunk of actual time spent and would otherwise consume valuable cycles.

Structs

Builder

Builder for creating an upkeep task.

Clock

Unified clock for taking measurements.

Handle

Handle to a running upkeep task.

Instant

A point-in-time wall-clock measurement.

Mock

Controllable time source for use in tests.

Traits

IntoNanoseconds

Type which can be converted into a nanosecond representation.