mirror of
https://github.com/hinto-janai/cuprate.git
synced 2025-01-24 19:35:57 +00:00
create {Benchmark, Stats, fn}
mappings
This commit is contained in:
parent
79ed8a5267
commit
e0f5dc6043
4 changed files with 64 additions and 35 deletions
|
@ -5,6 +5,7 @@ use std::{
|
|||
borrow::Cow,
|
||||
collections::BTreeSet,
|
||||
path::{Path, PathBuf},
|
||||
time::Instant,
|
||||
};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -37,24 +38,43 @@ use crate::config::Config;
|
|||
IntoStaticStr,
|
||||
VariantArray,
|
||||
)]
|
||||
pub(crate) enum Benchmarks {
|
||||
/// TODO
|
||||
pub(crate) enum Benchmark {
|
||||
/// Maps to [`env_open`].
|
||||
EnvOpen,
|
||||
}
|
||||
|
||||
impl Benchmark {
|
||||
/// Map [`Benchmark`] to the proper benchmark function.
|
||||
#[inline(always)]
|
||||
fn benchmark_fn(self) -> fn(&ConcreteEnv) {
|
||||
match self {
|
||||
Self::EnvOpen => env_open,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Stats
|
||||
/// TODO
|
||||
#[derive(Clone, Copy, PartialEq, PartialOrd, Serialize, Deserialize, Debug)]
|
||||
struct Stats {
|
||||
/// TODO
|
||||
/// Timings for [`env_open`].
|
||||
env_open: Option<f32>,
|
||||
}
|
||||
|
||||
impl Stats {
|
||||
/// TODO
|
||||
/// Create a new [`Stats`] with no benchmark timings.
|
||||
const fn new() -> Self {
|
||||
Self { env_open: None }
|
||||
}
|
||||
|
||||
/// This maps [`Benchmark`]s to a specific field in [`Stats`]
|
||||
/// which then gets updated to the passed `time`.
|
||||
#[inline(always)]
|
||||
fn update_benchmark_time(&mut self, benchmark: Benchmark, time: f32) {
|
||||
*match benchmark {
|
||||
Benchmark::EnvOpen => &mut self.env_open,
|
||||
} = Some(time);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- TODO
|
||||
|
@ -79,6 +99,8 @@ impl Drop for Benchmarker {
|
|||
//---------------------------------------------------------------------------------------------------- Impl
|
||||
impl Benchmarker {
|
||||
/// TODO
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
pub(crate) const fn new(env: ConcreteEnv, config: Config) -> Self {
|
||||
Self {
|
||||
env,
|
||||
|
@ -87,13 +109,33 @@ impl Benchmarker {
|
|||
}
|
||||
}
|
||||
|
||||
/// TODO
|
||||
pub(crate) fn bench(self) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
/// TODO
|
||||
pub(crate) fn todo(&mut self) {
|
||||
println!("TODO");
|
||||
/// Start all benchmark that are selected by the user.
|
||||
/// `main()` calls this once.
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
pub(crate) fn bench_all(mut self) {
|
||||
for benchmark in &self.config.benchmark_set {
|
||||
bench(*benchmark, &self.env, &mut self.stats);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Benchmark functions
|
||||
/// TODO
|
||||
#[inline(always)]
|
||||
fn bench(benchmark: Benchmark, env: &ConcreteEnv, stats: &mut Stats) {
|
||||
// Start the benchmark timer.
|
||||
let instant = Instant::now();
|
||||
|
||||
// Benchmark.
|
||||
benchmark.benchmark_fn()(env);
|
||||
|
||||
// Update the time.
|
||||
stats.update_benchmark_time(benchmark, instant.elapsed().as_secs_f32());
|
||||
}
|
||||
|
||||
/// TODO
|
||||
#[inline(always)]
|
||||
fn env_open(env: &ConcreteEnv) {
|
||||
println!("TODO");
|
||||
}
|
|
@ -10,16 +10,16 @@ use std::{
|
|||
use serde::{Deserialize, Serialize};
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use crate::{benchmarks::Benchmarks, cli::Cli};
|
||||
use crate::{bench::Benchmark, cli::Cli};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Config
|
||||
/// TODO
|
||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Serialize, Deserialize)]
|
||||
pub struct Config {
|
||||
pub(crate) struct Config {
|
||||
/// TODO
|
||||
iterations: usize,
|
||||
pub(crate) iterations: usize,
|
||||
/// TODO
|
||||
benchmark_set: BTreeSet<Benchmarks>,
|
||||
pub(crate) benchmark_set: BTreeSet<Benchmark>,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
|
@ -27,7 +27,7 @@ impl Config {
|
|||
pub(crate) fn new() -> Self {
|
||||
Self {
|
||||
iterations: 100_000,
|
||||
benchmark_set: Benchmarks::iter().collect(),
|
||||
benchmark_set: Benchmark::iter().collect(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -57,6 +57,7 @@
|
|||
// TODO: should be removed after all `todo!()`'s are gone.
|
||||
clippy::diverging_sub_expression,
|
||||
|
||||
clippy::inline_always,
|
||||
clippy::module_name_repetitions,
|
||||
clippy::module_inception,
|
||||
clippy::redundant_pub_crate,
|
||||
|
@ -69,12 +70,11 @@
|
|||
// Import private modules, export public types.
|
||||
//
|
||||
// Documentation for each module is located in the respective file.
|
||||
mod benchmarks;
|
||||
mod bench;
|
||||
mod cli;
|
||||
mod config;
|
||||
mod constants;
|
||||
mod free;
|
||||
mod state;
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Private
|
||||
|
||||
|
@ -113,7 +113,7 @@ fn main() {
|
|||
};
|
||||
|
||||
// Print config before starting.
|
||||
println!("{config:#?}");
|
||||
eprintln!("cuprate-database-benchmark configuration:\n{config:#?}");
|
||||
|
||||
// If `dry_run`, exit cleanly.
|
||||
if cli.dry_run {
|
||||
|
@ -124,6 +124,6 @@ fn main() {
|
|||
let env = cuprate_database::ConcreteEnv::open(db_config).unwrap();
|
||||
|
||||
// Start benchmarking/tests.
|
||||
let mut benchmarker = crate::benchmarks::Benchmarker::new(env, todo!());
|
||||
benchmarker.todo();
|
||||
let mut benchmarker = crate::bench::Benchmarker::new(env, todo!());
|
||||
benchmarker.bench_all();
|
||||
}
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
//! TODO
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Import
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Config
|
||||
/// TODO
|
||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub struct State {}
|
Loading…
Reference in a new issue