Expand description
Log-linear bucket histogram with significant-digit precision.
Each value is mapped to a bucket index built from two pieces:
- Major bucket:
floor(log2(value)) - log2(sub_count) + 1, clamped at 0. Each major covers a doubling range (1, 2, 4, 8, …). - Sub-bucket: linear position within the major range.
Together they give constant relative error within the significant-digit
precision: a value’s bucket is never wider than 1 / sub_count of the value
itself. sub_count is 2 * 10^d rounded up to a power of two, so d = 3
gives 2^11 = 2048 sub-buckets and a worst-case quantisation error of
1/2048 (0.049%), inside the half-unit-in-the-third-digit that three
significant digits demands.
The counter array starts at sub_count entries and grows lazily to cover
the largest value recorded: at d = 3 a range topping out at 10^6 lands at
index 20290 (~20k counters, 163 KB), and one topping out at 10^9 at index
40678 (~41k counters, 326 KB).
use subms_hdr_histogram::HdrHistogram;
let mut h = HdrHistogram::new(3);
for v in [10u64, 20, 30, 40, 50] { h.record(v); }
assert_eq!(h.count(), 5);
let p50 = h.value_at_percentile(0.5);
assert!((20..=30).contains(&p50), "p50={p50}");
assert_eq!(h.max(), 50);Full writeup, design notes and measured benchmarks: https://www.submillisecond.com/cookbook/recipes/subms-hdr-histogram
Re-exports§
pub use features::concurrent_writes::ConcurrentHdrHistogram;pub use features::decay::Clock;pub use features::decay::DecayingHdrHistogram;pub use features::decay::ManualClock;pub use features::dual_recorder::DualRecorder;pub use features::iterators::HdrLinearIter;pub use features::iterators::HdrLogarithmicIter;pub use features::iterators::HdrPercentileIter;pub use features::iterators::IterEntry;pub use features::merge::merge;pub use features::value_tagging::TaggedHdrHistogram;
Modules§
- features
- Opt-in feature modules. Each entry is gated by its own Cargo
feature; the base
HdrHistograminlib.rsstays zero-dep + std-only. - growth
SubMsGrowthRecipeimpl.- recipe
SubMsRecipeimpl.
Structs§
- HdrHistogram
- Histogram with
significant_digitsof precision in[1, 5].