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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
use std::process::Child; use criterion_plot::prelude::*; use super::*; use crate::report::{BenchmarkId, ComparisonData, MeasurementData, ReportContext}; use crate::measurement::ValueFormatter; fn iteration_times_figure( formatter: &dyn ValueFormatter, measurements: &MeasurementData<'_>, size: Option<Size>, ) -> Figure { let data = &measurements.avg_times; let max_avg_time = data.max(); let mut scaled_y: Vec<_> = data.iter().map(|(f, _)| f).collect(); let unit = formatter.scale_values(max_avg_time, &mut scaled_y); let scaled_y = Sample::new(&scaled_y); let mut figure = Figure::new(); figure .set(Font(DEFAULT_FONT)) .set(size.unwrap_or(SIZE)) .configure(Axis::BottomX, |a| { a.configure(Grid::Major, |g| g.show()).set(Label("Sample")) }) .configure(Axis::LeftY, |a| { a.configure(Grid::Major, |g| g.show()) .set(Label(format!("Average Iteration Time ({})", unit))) }) .plot( Points { x: 1..(data.len() + 1), y: scaled_y.as_ref(), }, |c| { c.set(DARK_BLUE) .set(PointSize(0.5)) .set(PointType::FilledCircle) }, ); figure } pub(crate) fn iteration_times( id: &BenchmarkId, context: &ReportContext, formatter: &dyn ValueFormatter, measurements: &MeasurementData<'_>, size: Option<Size>, ) -> Child { let mut figure = iteration_times_figure(formatter, measurements, size); figure.set(Title(gnuplot_escape(id.as_title()))); figure.configure(Key, |k| { k.set(Justification::Left) .set(Order::SampleText) .set(Position::Inside(Vertical::Top, Horizontal::Left)) }); let path = context.report_path(id, "iteration_times.svg"); debug_script(&path, &figure); figure.set(Output(path)).draw().unwrap() } pub(crate) fn iteration_times_small( id: &BenchmarkId, context: &ReportContext, formatter: &dyn ValueFormatter, measurements: &MeasurementData<'_>, size: Option<Size>, ) -> Child { let mut figure = iteration_times_figure(formatter, measurements, size); figure.configure(Key, |k| k.hide()); let path = context.report_path(id, "iteration_times_small.svg"); debug_script(&path, &figure); figure.set(Output(path)).draw().unwrap() } fn iteration_times_comparison_figure( formatter: &dyn ValueFormatter, measurements: &MeasurementData<'_>, comparison: &ComparisonData, size: Option<Size>, ) -> Figure { let current_data = &measurements.avg_times; let base_data = &comparison.base_avg_times; let mut all_data: Vec<f64> = current_data.iter().map(|(f, _)| f).collect(); all_data.extend_from_slice(base_data); let typical_value = Sample::new(&all_data).max(); let unit = formatter.scale_values(typical_value, &mut all_data); let (scaled_current_y, scaled_base_y) = all_data.split_at(current_data.len()); let scaled_current_y = Sample::new(scaled_current_y); let scaled_base_y = Sample::new(scaled_base_y); let mut figure = Figure::new(); figure .set(Font(DEFAULT_FONT)) .set(size.unwrap_or(SIZE)) .configure(Axis::BottomX, |a| { a.configure(Grid::Major, |g| g.show()).set(Label("Sample")) }) .configure(Axis::LeftY, |a| { a.configure(Grid::Major, |g| g.show()) .set(Label(format!("Average Iteration Time ({})", unit))) }) .configure(Key, |k| { k.set(Justification::Left) .set(Order::SampleText) .set(Position::Inside(Vertical::Top, Horizontal::Left)) }) .plot( Points { x: 1..(current_data.len() + 1), y: scaled_base_y.as_ref(), }, |c| { c.set(DARK_RED) .set(Label("Base")) .set(PointSize(0.5)) .set(PointType::FilledCircle) }, ) .plot( Points { x: 1..(current_data.len() + 1), y: scaled_current_y.as_ref(), }, |c| { c.set(DARK_BLUE) .set(Label("Current")) .set(PointSize(0.5)) .set(PointType::FilledCircle) }, ); figure } pub(crate) fn iteration_times_comparison( id: &BenchmarkId, context: &ReportContext, formatter: &dyn ValueFormatter, measurements: &MeasurementData<'_>, comparison: &ComparisonData, size: Option<Size>, ) -> Child { let mut figure = iteration_times_comparison_figure(formatter, measurements, comparison, size); figure.set(Title(gnuplot_escape(id.as_title()))); let path = context.report_path(id, "both/iteration_times.svg"); debug_script(&path, &figure); figure.set(Output(path)).draw().unwrap() } pub(crate) fn iteration_times_comparison_small( id: &BenchmarkId, context: &ReportContext, formatter: &dyn ValueFormatter, measurements: &MeasurementData<'_>, comparison: &ComparisonData, size: Option<Size>, ) -> Child { let mut figure = iteration_times_comparison_figure(formatter, measurements, comparison, size); figure.configure(Key, |k| k.hide()); let path = context.report_path(id, "relative_iteration_times_small.svg"); debug_script(&path, &figure); figure.set(Output(path)).draw().unwrap() }