alloc_test/perf/
benchmark.rs

1use super::measure::PerfStats;
2
3pub fn perf_benchmark<F: Fn() -> O, O>(id: &str, f: F) -> PerfStats {
4    let stats = super::measure::bench(f);
5    log!("\nperformance stats for `{id}`:\n{stats}");
6    stats
7}
8
9pub fn perf_log_toml<F: Fn() -> O, O>(id: &str, f: F) -> PerfStats {
10    let stats = super::measure::bench(f);
11    log!(
12        "\nperformance stats for `{id}`:\n{stats}",
13        stats = toml::to_string(&stats).unwrap()
14    );
15    stats
16}
17
18#[macro_export]
19macro_rules! perf_bench {
20    ($test:ident, $thresh:expr) => {
21        $crate::threshold::check_threshold_with_args(
22            || $crate::perf::benchmark::perf_benchmark(stringify!($test), $test),
23            "perf_bench",
24            stringify!($test),
25            $thresh,
26        )
27    };
28}
29
30#[macro_export]
31macro_rules! perf_bench_cmp_with_toml {
32    ($test:ident $(,)?) => {{
33        let value = $crate::perf::benchmark::perf_log_toml(stringify!($test), $test);
34        Result::<
35            $crate::perf::measure::PerfStats,
36            $crate::threshold::CheckThresholdError<$crate::perf::compare::PerfThresholdsError>,
37        >::Ok(value)
38    }};
39    ($test:ident, $toml:expr, $limits:expr $(,)?) => {{
40        $crate::threshold::check_threshold_with_str(
41            || $crate::perf::benchmark::perf_benchmark(stringify!($test), $test),
42            $toml,
43            $limits,
44        )
45    }};
46}