criterion/plot/gnuplot_backend/
t_test.rs

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