Expand description
Histograms with a configurable number of buckets, and a terminal-friendly
Display
.
This crate provides a Histogram
type that allows configuration of the
number of buckets that will be used, regardless of the range of input
samples. This is useful when displaying a Histogram
(for example, when
printing it to a terminal) but it sacrifices fancy tracking of precision and
significant figures.
It uses O(n) memory.
extern crate histo_fp;
use histo_fp::Histogram;
// Create a histogram that will have 10 buckets.
let mut histogram = Histogram::with_buckets(10, Some(2));
// Adds some samples to the histogram.
for sample in 0..100 {
histogram.add(sample as f64);
histogram.add((sample * sample) as f64);
}
// Iterate over buckets and do stuff with their range and count.
for bucket in histogram.buckets() {
do_stuff(bucket.start(), bucket.end(), bucket.count());
}
// And you can also `Display` a histogram!
println!("{}", histogram);
// Prints:
//
// ```
// # Number of samples = 200
// # Min = 0
// # Max = 9801
// #
// # Mean = 1666.5000000000005
// # Standard deviation = 2641.2281518263426
// # Variance = 6976086.1499999985
// #
// # Each ∎ is a count of 2
// #
// 0 .. 980 [ 132 ]: ∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎
// 980 .. 1960 [ 13 ]: ∎∎∎∎∎∎
// 1960 .. 2940 [ 10 ]: ∎∎∎∎∎
// 2940 .. 3920 [ 8 ]: ∎∎∎∎
// 3920 .. 4900 [ 7 ]: ∎∎∎
// 4900 .. 5880 [ 7 ]: ∎∎∎
// 5880 .. 6860 [ 6 ]: ∎∎∎
// 6860 .. 7840 [ 6 ]: ∎∎∎
// 7840 .. 8820 [ 5 ]: ∎∎
// 8820 .. 9800 [ 6 ]: ∎∎∎
// ```
Structs§
- A bucket is a range of samples and their count.
- An iterator over the buckets in a histogram.
- A histogram is a collection of samples, sorted into buckets.