1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet};
use crate::benchmark_comparison::BenchmarkComparison;

/// Result of the comparison of two benchmarks
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AnalysisResult {
    name: String,
    new_series: HashSet<String>,
    results: HashMap<String, BenchmarkComparison>,
}

impl AnalysisResult {
    pub(crate) fn new(name: String) -> AnalysisResult {
        AnalysisResult {
            name,
            new_series: Default::default(),
            results: Default::default(),
        }
    }

    pub(crate) fn add_new(&mut self, name: String) {
        self.new_series.insert(name);
    }

    pub(crate) fn add(&mut self, name: String, ordering: BenchmarkComparison) {
        self.results.insert(name, ordering);
    }

    /// Name of the [crate::benchmarks::Benchmarks] suite that was analyzed
    pub fn name(&self) -> &String {
        &self.name
    }

    /// Names of series that are new in the current run
    pub fn new_series(&self) -> &HashSet<String> {
        &self.new_series
    }

    /// [BenchmarkComparison] values for each series
    pub fn results(&self) -> &HashMap<String, BenchmarkComparison> {
        &self.results
    }
}

impl ToString for AnalysisResult {
    /// Produce a pretty printed JSON string of this result
    fn to_string(&self) -> String {
        serde_json::to_string_pretty(&self).unwrap()
    }
}