Crate histogram [] [src]

A native rust implementation of a histogram and percentiles which can offer specified precision across the full range of stored values. This library is inspired by the HdrHistogram project.

Goals

  • maintain precision across full value range
  • provide percentile metrics for stored data
  • pre-allocated datastructure

Future work

  • unknown

Usage

Create a new histogram, call increment for every value, retrieve percentile stats.

Example

Create a histogram, increment values, show percentiles


use histogram::*;

let mut histogram = Histogram::new(
    HistogramConfig {
        precision: 4,       // maintain > 4 sigfigs (max error .01%)
        max_value: 1000000, // max storable value. fewer, less ram needed
        max_memory: 0,      // optional memory bound in Bytes. 0 = unlimited
    }
).unwrap();

let mut value = 0;

for i in 1..100 {
    histogram.increment(i);
}

// print percentiles from the histogram
println!("Percentiles: p50: {} ns p90: {} ns p99: {} ns p999: {}",
    histogram.percentile(50.0).unwrap(),
    histogram.percentile(90.0).unwrap(),
    histogram.percentile(99.0).unwrap(),
    histogram.percentile(99.9).unwrap(),
);

Structs

Histogram
HistogramBucket
HistogramConfig
HistogramCounters
HistogramData
HistogramProperties