histogram

Struct Histogram

Source
pub struct Histogram { /* private fields */ }
Expand description

the main datastructure

Implementations§

Source§

impl Histogram

Source

pub fn new() -> Histogram

create a new Histogram

§Example
let mut h = Histogram::new();
Source

pub fn configure() -> Config

configure a Histogram

§Example
let mut h = Histogram::configure()
    .max_value(10_000)
    .build()
    .unwrap();
Source

pub fn clear(&mut self)

clear the histogram data

§Example
let mut h = Histogram::new();

h.increment(1);
assert_eq!(h.entries(), 1);
h.clear();
assert_eq!(h.entries(), 0);
Source

pub fn increment(&mut self, value: u64) -> Result<(), &'static str>

increment the count for a value

§Example
use histogram::Histogram;

let mut h = Histogram::new();

h.increment(1);
assert_eq!(h.get(1).unwrap(), 1);
Source

pub fn increment_by( &mut self, value: u64, count: u64, ) -> Result<(), &'static str>

record additional counts for value

§Example
let mut h = Histogram::new();

h.increment_by(1, 1);
assert_eq!(h.get(1).unwrap(), 1);

h.increment_by(2, 2);
assert_eq!(h.get(2).unwrap(), 2);

h.increment_by(10, 10);
assert_eq!(h.get(10).unwrap(), 10);
Source

pub fn decrement(&mut self, value: u64) -> Result<(), &'static str>

decrement the count for a value. This functionality is best used to remove previously inserted from the histogram.

§Example
let mut h = Histogram::new();

h.increment(1).unwrap();
assert_eq!(h.get(1).unwrap(), 1);
h.decrement(1).unwrap();
assert_eq!(h.get(1).unwrap(), 0);
Source

pub fn decrement_by( &mut self, value: u64, count: u64, ) -> Result<(), &'static str>

remove count for value from histogram. This functionality is best used to remove previously inserted from the histogram.

§Example
let mut h = Histogram::new();

h.increment_by(1, 1).unwrap();
h.increment_by(2, 2).unwrap();
h.decrement_by(1, 1).unwrap();

assert_eq!(h.get(2).unwrap(), 2);
assert_eq!(h.get(1).unwrap(), 0);
Source

pub fn get(&self, value: u64) -> Option<u64>

get the count for a value

§Example
let mut h = Histogram::new();
assert_eq!(h.get(1).unwrap(), 0);
Source

pub fn percentile(&self, percentile: f64) -> Result<u64, &'static str>

return the value for the given percentile

§Example
let mut h = Histogram::new();
for value in 1..1000 {
    h.increment(value).unwrap();
}

assert_eq!(h.percentile(50.0).unwrap(), 501);
assert_eq!(h.percentile(90.0).unwrap(), 901);
assert_eq!(h.percentile(99.0).unwrap(), 991);
assert_eq!(h.percentile(99.9).unwrap(), 999);
Source

pub fn minimum(&self) -> Result<u64, &'static str>

convenience function for min

§Example
let mut h = Histogram::new();
for value in 1..1000 {
    h.increment(value);
}
assert_eq!(h.minimum().unwrap(), 1);
Source

pub fn maximum(&self) -> Result<u64, &'static str>

convenience function for max

§Example
let mut h = Histogram::new();
for value in 1..1000 {
    h.increment(value);
}
assert_eq!(h.maximum().unwrap(), 999);
Source

pub fn mean(&self) -> Result<u64, &'static str>

arithmetic mean approximation across the histogram

§Example
let mut h = Histogram::new();
for value in 1..1000 {
    h.increment(value);
}
assert_eq!(h.mean().unwrap(), 500);
Source

pub fn stdvar(&self) -> Result<u64, &'static str>

standard variance approximation across the histogram

§Example
let mut h = Histogram::new();
for value in 1..11 {
    h.increment(value);
}
assert_eq!(h.stdvar().unwrap(), 9);
Source

pub fn stddev(&self) -> Option<u64>

standard deviation approximation across the histogram

§Example
let mut h = Histogram::new();

for value in 1..11 {
    h.increment(value);
}

assert_eq!(h.stddev().unwrap(), 3);

h.clear();

for value in 1..4 {
    h.increment(value);
}
for _ in 0..26 {
    h.increment(1);
}

assert_eq!(h.stddev().unwrap(), 1);
Source

pub fn merge(&mut self, other: &Histogram)

merge one Histogram into another Histogram

§Example
let mut a = Histogram::new();
let mut b = Histogram::new();

assert_eq!(a.entries(), 0);
assert_eq!(b.entries(), 0);

a.increment(1);
b.increment(2);

assert_eq!(a.entries(), 1);
assert_eq!(b.entries(), 1);

a.merge(&mut b);

assert_eq!(a.entries(), 2);
assert_eq!(a.get(1).unwrap(), 1);
assert_eq!(a.get(2).unwrap(), 1);
Source

pub fn entries(&self) -> u64

return the number of entries in the Histogram

§Example
let mut h = Histogram::new();

assert_eq!(h.entries(), 0);
h.increment(1);
assert_eq!(h.entries(), 1);
Source

pub fn buckets_total(&self) -> u64

return the number of buckets in the Histogram

§Example
let mut h = Histogram::new();

assert!(h.buckets_total() > 1);

Trait Implementations§

Source§

impl Clone for Histogram

Source§

fn clone(&self) -> Histogram

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Histogram

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Histogram

Source§

fn default() -> Histogram

Returns the “default value” for a type. Read more
Source§

impl<'a> IntoIterator for &'a Histogram

Source§

type Item = Bucket

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.