latency
low-latency timing library for performance-critical applications. provides nanosecond-precision measurements using x86_64 tsc (time-stamp counter) with minimal overhead.
features
- cpu cycle counting via
rdtsc/rdtscpon x86_64 - lock-free histogram with logarithmic bucketing for latency distributions
- multiple timer apis manual, raii guards, scoped timers
- zero-cost when disabled via feature flag
- fast statistics percentiles (p50, p90, p99, p999, p9999) with o(1) bucket access
quick start
use ;
use Arc;
api
timing primitives
TimePoint::now()- snapshot of current tsc valueTimePoint::elapsed_ns()/elapsed_cycles()- elapsed time since snapshottime_block!macro - time a code block and get result + elapsed timetime_if_enabled!macro - conditional timing based on feature flag
histograms
Histogram::record(value_ns)- lock-free atomic recordinghistogram.stats()- get latencystats with percentileshistogram.percentiles(&[p1, p2, ...])- arbitrary percentile queries
timers
Timer- manual start/stop with optional histogram recordingTimerGuard- raii guard that records on dropScopedTimer- closures with threshold-based logging
global registry (optional)
let hist = histogram;
report_all; // print all histograms
configuration
add to Cargo.toml:
[]
= { = "." }
[]
= ["enabled"]
disable timing overhead:
= [] # timing disabled by default
performance
rdtsc()– ~20 cycles (inline)histogram.record()– ~50 cycles atomic update (lock-free)- when disabled – zero runtime cost via feature flag
x86_64 only
requires x86_64 for tsc access. other platforms return 0 with feature checks.