alloc_test/alloc/
benchmark.rs1use super::measure::MemoryStats;
2
3pub fn alloc_benchmark<F: FnOnce() -> O, O>(id: &str, f: F) -> MemoryStats {
4 let (_, stats) = crate::alloc::measure::trace_allocs(f);
5 log!("\nmemory allocation stats for `{id}`:\n{stats}");
6 stats
7}
8
9pub fn alloc_log_toml<F: Fn() -> O, O>(id: &str, f: F) -> MemoryStats {
10 let (_, stats) = super::measure::trace_allocs(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! alloc_bench {
20 ($test:ident, $thresh:expr) => {
21 $crate::threshold::check_threshold_with_args(
22 || $crate::alloc::benchmark::alloc_benchmark(stringify!($test), $test),
23 "alloc_bench",
24 stringify!($test),
25 $thresh,
26 )
27 };
28}
29
30#[macro_export]
31macro_rules! alloc_bench_cmp_with_toml {
32 ($test:ident $(,)?) => {{
33 let value = $crate::alloc::benchmark::alloc_log_toml(stringify!($test), $test);
34 Result::<
35 $crate::alloc::measure::MemoryStats,
36 $crate::threshold::CheckThresholdError<$crate::alloc::compare::AllocThresholdsError>,
37 >::Ok(value)
38 }};
39 ($test:ident, $toml:expr, $limits:expr $(,)?) => {{
40 $crate::threshold::check_threshold_with_str(
41 || $crate::alloc::benchmark::alloc_benchmark(stringify!($test), $test),
42 $toml,
43 $limits,
44 )
45 }};
46}