| 1 | use std::iter; |
| 2 | use std::process::Child; |
| 3 | |
| 4 | use criterion_plot::prelude::*; |
| 5 | |
| 6 | use super::*; |
| 7 | use crate::kde; |
| 8 | use crate::report::{BenchmarkId, ComparisonData, MeasurementData, ReportContext}; |
| 9 | |
| 10 | pub(crate) fn t_test( |
| 11 | id: &BenchmarkId, |
| 12 | context: &ReportContext, |
| 13 | _measurements: &MeasurementData<'_>, |
| 14 | comparison: &ComparisonData, |
| 15 | size: Option<Size>, |
| 16 | ) -> Child { |
| 17 | let t = comparison.t_value; |
| 18 | let (xs, ys) = kde::sweep(&comparison.t_distribution, KDE_POINTS, None); |
| 19 | let zero = iter::repeat(0); |
| 20 | |
| 21 | let mut figure = Figure::new(); |
| 22 | figure |
| 23 | .set(Font(DEFAULT_FONT)) |
| 24 | .set(size.unwrap_or(SIZE)) |
| 25 | .set(Title(format!( |
| 26 | "{}: Welch t test" , |
| 27 | gnuplot_escape(id.as_title()) |
| 28 | ))) |
| 29 | .configure(Axis::BottomX, |a| a.set(Label("t score" ))) |
| 30 | .configure(Axis::LeftY, |a| a.set(Label("Density" ))) |
| 31 | .configure(Key, |k| { |
| 32 | k.set(Justification::Left) |
| 33 | .set(Order::SampleText) |
| 34 | .set(Position::Outside(Vertical::Top, Horizontal::Right)) |
| 35 | }) |
| 36 | .plot( |
| 37 | FilledCurve { |
| 38 | x: &*xs, |
| 39 | y1: &*ys, |
| 40 | y2: zero, |
| 41 | }, |
| 42 | |c| { |
| 43 | c.set(DARK_BLUE) |
| 44 | .set(Label("t distribution" )) |
| 45 | .set(Opacity(0.25)) |
| 46 | }, |
| 47 | ) |
| 48 | .plot( |
| 49 | Lines { |
| 50 | x: &[t, t], |
| 51 | y: &[0, 1], |
| 52 | }, |
| 53 | |c| { |
| 54 | c.set(Axes::BottomXRightY) |
| 55 | .set(DARK_BLUE) |
| 56 | .set(LINEWIDTH) |
| 57 | .set(Label("t statistic" )) |
| 58 | .set(LineType::Solid) |
| 59 | }, |
| 60 | ); |
| 61 | |
| 62 | let path = context.report_path(id, "change/t-test.svg" ); |
| 63 | debug_script(&path, &figure); |
| 64 | figure.set(Output(path)).draw().unwrap() |
| 65 | } |
| 66 | |