2 use std::collections::BTreeMap;
4 #[derive(Clone, PartialEq, Debug, Copy)]
11 pub fn new(value: f64, noise: f64) -> Metric {
12 Metric { value, noise }
16 #[derive(Clone, PartialEq)]
17 pub struct MetricMap(BTreeMap<String, Metric>);
20 pub fn new() -> MetricMap {
21 MetricMap(BTreeMap::new())
24 /// Insert a named `value` (+/- `noise`) metric into the map. The value
25 /// must be non-negative. The `noise` indicates the uncertainty of the
26 /// metric, which doubles as the "noise range" of acceptable
27 /// pairwise-regressions on this named value, when comparing from one
28 /// metric to the next using `compare_to_old`.
30 /// If `noise` is positive, then it means this metric is of a value
31 /// you want to see grow smaller, so a change larger than `noise` in the
32 /// positive direction represents a regression.
34 /// If `noise` is negative, then it means this metric is of a value
35 /// you want to see grow larger, so a change larger than `noise` in the
36 /// negative direction represents a regression.
37 pub fn insert_metric(&mut self, name: &str, value: f64, noise: f64) {
38 let m = Metric { value, noise };
39 self.0.insert(name.to_owned(), m);
42 pub fn fmt_metrics(&self) -> String {
46 .map(|(k, v)| format!("{}: {} (+/- {})", *k, v.value, v.noise))