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::*;

// create a histogram with default config
let mut histogram = Histogram::new().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(),
);

// print additional statistics
println!("Latency (ns): Min: {} Avg: {} Max: {} StdDev: {}",
    histogram.minimum().unwrap(),
    histogram.mean().unwrap(),
    histogram.maximum().unwrap(),
    histogram.stddev().unwrap(),
);

Structs

Histogram
HistogramBucket
HistogramConfig
HistogramCounters
HistogramData
HistogramProperties