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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
mod gnuplot_backend; mod plotters_backend; pub(crate) use gnuplot_backend::Gnuplot; pub(crate) use plotters_backend::PlottersBackend; use crate::estimate::Statistic; use crate::measurement::ValueFormatter; use crate::report::{BenchmarkId, ComparisonData, MeasurementData, ReportContext, ValueType}; use std::path::PathBuf; const REPORT_STATS: [Statistic; 7] = [ Statistic::Typical, Statistic::Slope, Statistic::Mean, Statistic::Median, Statistic::MedianAbsDev, Statistic::MedianAbsDev, Statistic::StdDev, ]; const CHANGE_STATS: [Statistic; 2] = [Statistic::Mean, Statistic::Median]; #[derive(Clone, Copy)] pub(crate) struct PlotContext<'a> { pub(crate) id: &'a BenchmarkId, pub(crate) context: &'a ReportContext, pub(crate) size: Option<(usize, usize)>, pub(crate) is_thumbnail: bool, } impl<'a> PlotContext<'a> { pub fn size(mut self, s: Option<criterion_plot::Size>) -> PlotContext<'a> { if let Some(s) = s { self.size = Some((s.0, s.1)); } self } pub fn thumbnail(mut self, value: bool) -> PlotContext<'a> { self.is_thumbnail = value; self } pub fn line_comparison_path(&self) -> PathBuf { let mut path = self.context.output_directory.clone(); path.push(self.id.as_directory_name()); path.push("report"); path.push("lines.svg"); path } pub fn violin_path(&self) -> PathBuf { let mut path = self.context.output_directory.clone(); path.push(self.id.as_directory_name()); path.push("report"); path.push("violin.svg"); path } } #[derive(Clone, Copy)] pub(crate) struct PlotData<'a> { pub(crate) formatter: &'a dyn ValueFormatter, pub(crate) measurements: &'a MeasurementData<'a>, pub(crate) comparison: Option<&'a ComparisonData>, } impl<'a> PlotData<'a> { pub fn comparison(mut self, comp: &'a ComparisonData) -> PlotData<'a> { self.comparison = Some(comp); self } } pub(crate) trait Plotter { fn pdf(&mut self, ctx: PlotContext<'_>, data: PlotData<'_>); fn regression(&mut self, ctx: PlotContext<'_>, data: PlotData<'_>); fn iteration_times(&mut self, ctx: PlotContext<'_>, data: PlotData<'_>); fn abs_distributions(&mut self, ctx: PlotContext<'_>, data: PlotData<'_>); fn rel_distributions(&mut self, ctx: PlotContext<'_>, data: PlotData<'_>); fn line_comparison( &mut self, ctx: PlotContext<'_>, formatter: &dyn ValueFormatter, all_curves: &[&(&BenchmarkId, Vec<f64>)], value_type: ValueType, ); fn violin( &mut self, ctx: PlotContext<'_>, formatter: &dyn ValueFormatter, all_curves: &[&(&BenchmarkId, Vec<f64>)], ); fn t_test(&mut self, ctx: PlotContext<'_>, data: PlotData<'_>); fn wait(&mut self); }