Skip to main content

kermit_bench/benchmarks/
mod.rs

1use {crate::benchmark::BenchmarkConfig, clap::ValueEnum, std::str::FromStr};
2
3pub mod oxford;
4
5/// The set of available benchmarks.
6///
7/// Each variant maps to a [`BenchmarkConfig`] implementation that knows how to
8/// download, transform, and validate its dataset.
9#[derive(Copy, Clone, PartialEq, Eq, Debug, ValueEnum)]
10pub enum Benchmark {
11    Oxford,
12}
13
14impl Benchmark {
15    pub fn from_name(name: &str) -> Result<Self, Box<dyn std::error::Error>> {
16        if name == Benchmark::Oxford.name() {
17            Ok(Self::Oxford)
18        } else {
19            Err(format!("Benchmark '{}' not found", name).into())
20        }
21    }
22
23    pub fn names() -> Vec<String> { vec![Self::Oxford.name()] }
24
25    pub fn name(self) -> String { self.config().metadata().name.to_string() }
26
27    pub fn config(self) -> Box<dyn BenchmarkConfig + 'static> {
28        match self {
29            | Self::Oxford => Box::new(oxford::OxfordBenchmark),
30        }
31    }
32}
33
34impl FromStr for Benchmark {
35    type Err = String;
36
37    fn from_str(s: &str) -> Result<Self, Self::Err> {
38        Self::from_name(s).map_err(|e| e.to_string())
39    }
40}