use crate::RuntimeInterface;
use serde::{Deserialize, Serialize};
use std::time::Duration;
pub mod benchmarks;
pub mod report;
pub mod runner;
pub mod stats;
pub use benchmarks::default_benchmarks;
pub use report::{
render_console_summary, write_html_comparison_report, write_html_report, write_json_report,
};
pub use runner::{
BenchAllocSnapshot, BenchAllocStats, BenchComparisonResult, BenchComparisonSummary,
BenchConfig, BenchOutput, BenchRunResult, BenchRunSummary, BenchRunner, BenchThresholds,
RegressionCheck, RegressionConfig, RegressionMetric, run_benchmark_comparison,
};
pub use stats::{Comparison, ComparisonConfidence, Stats, StatsError};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum BenchCategory {
TaskSpawn,
TaskSwitch,
ChannelThroughput,
ChannelLatency,
MutexContention,
TimerAccuracy,
IoThroughput,
IoLatency,
}
pub struct Benchmark<R: RuntimeInterface> {
pub id: &'static str,
pub name: &'static str,
pub description: &'static str,
pub category: BenchCategory,
pub warmup: u32,
pub iterations: u32,
pub bench_fn: Box<dyn Fn(&R) -> Duration + Send + Sync>,
}
impl<R: RuntimeInterface> Benchmark<R> {
pub fn new(
id: &'static str,
name: &'static str,
description: &'static str,
category: BenchCategory,
warmup: u32,
iterations: u32,
bench_fn: impl Fn(&R) -> Duration + Send + Sync + 'static,
) -> Self {
Self {
id,
name,
description,
category,
warmup,
iterations,
bench_fn: Box::new(bench_fn),
}
}
}
#[macro_export]
macro_rules! benchmark {
(
id: $id:literal,
name: $name:literal,
description: $desc:literal,
category: $cat:expr,
warmup: $warmup:expr,
iterations: $iters:expr,
bench: |$rt:ident| $body:expr
) => {
$crate::bench::Benchmark::new($id, $name, $desc, $cat, $warmup, $iters, |$rt| $body)
};
}