add tmp_env_all_threads()

This commit is contained in:
hinto.janai 2024-04-21 21:05:03 -04:00
parent 3ffa63789a
commit 207f4a1ca2
No known key found for this signature in database
GPG key ID: D47CE05FA175A499
9 changed files with 105 additions and 67 deletions

View file

@ -44,4 +44,5 @@ Each file represents some logical benchmark grouping.
| `db_multi_thread.rs` | Same as `db.rs` but multi-threaded
| `env.rs` | `trait {Env, EnvInner, TxR{o,w}, Tables[Mut]}` benchmarks
| `env_multi_thread.rs` | Same as `env.rs` but multi-threaded
| `service.rs` | `cuprate_database::service` benchmarks
| `storable.rs` | `trait Storable` benchmarks

View file

@ -1,4 +1,4 @@
//! TODO
//! `trait Database{Ro,Rw,Iter}` benchmarks.
use std::time::Instant;
@ -13,7 +13,7 @@ use cuprate_database::{
DatabaseIter, DatabaseRo, DatabaseRw, Env, EnvInner, TxRw,
};
use cuprate_database_benchmark::tmp_concrete_env;
use cuprate_database_benchmark::tmp_env;
//---------------------------------------------------------------------------------------------------- Criterion
criterion_group! {
@ -66,7 +66,7 @@ const VALUE: Output = Output {
/// [`DatabaseRo::get`]
#[named]
fn ro_get(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -88,7 +88,7 @@ fn ro_get(c: &mut Criterion) {
/// [`DatabaseRo::len`]
#[named]
fn ro_len(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -110,7 +110,7 @@ fn ro_len(c: &mut Criterion) {
/// [`DatabaseRo::first`]
#[named]
fn ro_first(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -132,7 +132,7 @@ fn ro_first(c: &mut Criterion) {
/// [`DatabaseRo::last`]
#[named]
fn ro_last(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -154,7 +154,7 @@ fn ro_last(c: &mut Criterion) {
/// [`DatabaseRo::is_empty`]
#[named]
fn ro_is_empty(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -176,7 +176,7 @@ fn ro_is_empty(c: &mut Criterion) {
/// [`DatabaseRo::contains`]
#[named]
fn ro_contains(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -203,7 +203,7 @@ fn ro_contains(c: &mut Criterion) {
/// [`DatabaseRo::get`]
#[named]
fn rw_get(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -225,7 +225,7 @@ fn rw_get(c: &mut Criterion) {
/// [`DatabaseRo::len`]
#[named]
fn rw_len(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -247,7 +247,7 @@ fn rw_len(c: &mut Criterion) {
/// [`DatabaseRo::first`]
#[named]
fn rw_first(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -269,7 +269,7 @@ fn rw_first(c: &mut Criterion) {
/// [`DatabaseRo::last`]
#[named]
fn rw_last(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -291,7 +291,7 @@ fn rw_last(c: &mut Criterion) {
/// [`DatabaseRo::is_empty`]
#[named]
fn rw_is_empty(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -313,7 +313,7 @@ fn rw_is_empty(c: &mut Criterion) {
/// [`DatabaseRo::contains`]
#[named]
fn rw_contains(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -336,7 +336,7 @@ fn rw_contains(c: &mut Criterion) {
/// [`DatabaseRw::put`]
#[named]
fn put(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -354,7 +354,7 @@ fn put(c: &mut Criterion) {
/// [`DatabaseRw::delete`]
#[named]
fn delete(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -383,7 +383,7 @@ fn delete(c: &mut Criterion) {
/// [`DatabaseRw::pop_first`]
#[named]
fn pop_first(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -412,7 +412,7 @@ fn pop_first(c: &mut Criterion) {
/// [`DatabaseRw::pop_last`]
#[named]
fn pop_last(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -442,7 +442,7 @@ fn pop_last(c: &mut Criterion) {
// /// [`DatabaseRw::take`]
// #[named]
// fn take(c: &mut Criterion) {
// let (env, _tempdir) = tmp_concrete_env();
// let (env, _tempdir) = tmp_env();
// let env_inner = env.env_inner();
// let tx_rw = env_inner.tx_rw().unwrap();
// let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -465,7 +465,7 @@ fn pop_last(c: &mut Criterion) {
/// [`DatabaseRo::get_range`]
#[named]
fn get_range(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -495,7 +495,7 @@ fn get_range(c: &mut Criterion) {
/// [`DatabaseRo::iter`]
#[named]
fn iter(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -525,7 +525,7 @@ fn iter(c: &mut Criterion) {
/// [`DatabaseRo::keys`]
#[named]
fn keys(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -555,7 +555,7 @@ fn keys(c: &mut Criterion) {
/// [`DatabaseRo::values`]
#[named]
fn values(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();

View file

@ -1,3 +1,4 @@
//! Same as `db.rs` but multi-threaded.
//! TODO: create multi-threaded benchmarks
use std::time::Instant;
@ -13,7 +14,7 @@ use cuprate_database::{
DatabaseIter, DatabaseRo, DatabaseRw, Env, EnvInner, TxRw,
};
use cuprate_database_benchmark::tmp_concrete_env;
use cuprate_database_benchmark::tmp_env_all_threads;
//---------------------------------------------------------------------------------------------------- Criterion
criterion_group! {
@ -66,7 +67,7 @@ const VALUE: Output = Output {
/// [`DatabaseRo::get`]
#[named]
fn ro_get(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env_all_threads();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -88,7 +89,7 @@ fn ro_get(c: &mut Criterion) {
/// [`DatabaseRo::len`]
#[named]
fn ro_len(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env_all_threads();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -110,7 +111,7 @@ fn ro_len(c: &mut Criterion) {
/// [`DatabaseRo::first`]
#[named]
fn ro_first(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env_all_threads();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -132,7 +133,7 @@ fn ro_first(c: &mut Criterion) {
/// [`DatabaseRo::last`]
#[named]
fn ro_last(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env_all_threads();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -154,7 +155,7 @@ fn ro_last(c: &mut Criterion) {
/// [`DatabaseRo::is_empty`]
#[named]
fn ro_is_empty(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env_all_threads();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -176,7 +177,7 @@ fn ro_is_empty(c: &mut Criterion) {
/// [`DatabaseRo::contains`]
#[named]
fn ro_contains(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env_all_threads();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -203,7 +204,7 @@ fn ro_contains(c: &mut Criterion) {
/// [`DatabaseRo::get`]
#[named]
fn rw_get(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env_all_threads();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -225,7 +226,7 @@ fn rw_get(c: &mut Criterion) {
/// [`DatabaseRo::len`]
#[named]
fn rw_len(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env_all_threads();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -247,7 +248,7 @@ fn rw_len(c: &mut Criterion) {
/// [`DatabaseRo::first`]
#[named]
fn rw_first(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env_all_threads();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -269,7 +270,7 @@ fn rw_first(c: &mut Criterion) {
/// [`DatabaseRo::last`]
#[named]
fn rw_last(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env_all_threads();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -291,7 +292,7 @@ fn rw_last(c: &mut Criterion) {
/// [`DatabaseRo::is_empty`]
#[named]
fn rw_is_empty(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env_all_threads();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -313,7 +314,7 @@ fn rw_is_empty(c: &mut Criterion) {
/// [`DatabaseRo::contains`]
#[named]
fn rw_contains(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env_all_threads();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -336,7 +337,7 @@ fn rw_contains(c: &mut Criterion) {
/// [`DatabaseRw::put`]
#[named]
fn put(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env_all_threads();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -354,7 +355,7 @@ fn put(c: &mut Criterion) {
/// [`DatabaseRw::delete`]
#[named]
fn delete(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env_all_threads();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -383,7 +384,7 @@ fn delete(c: &mut Criterion) {
/// [`DatabaseRw::pop_first`]
#[named]
fn pop_first(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env_all_threads();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -412,7 +413,7 @@ fn pop_first(c: &mut Criterion) {
/// [`DatabaseRw::pop_last`]
#[named]
fn pop_last(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env_all_threads();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -442,7 +443,7 @@ fn pop_last(c: &mut Criterion) {
// /// [`DatabaseRw::take`]
// #[named]
// fn take(c: &mut Criterion) {
// let (env, _tempdir) = tmp_concrete_env();
// let (env, _tempdir) = tmp_env_all_threads();
// let env_inner = env.env_inner();
// let tx_rw = env_inner.tx_rw().unwrap();
// let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -465,7 +466,7 @@ fn pop_last(c: &mut Criterion) {
/// [`DatabaseRo::get_range`]
#[named]
fn get_range(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env_all_threads();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -495,7 +496,7 @@ fn get_range(c: &mut Criterion) {
/// [`DatabaseRo::iter`]
#[named]
fn iter(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env_all_threads();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -525,7 +526,7 @@ fn iter(c: &mut Criterion) {
/// [`DatabaseRo::keys`]
#[named]
fn keys(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env_all_threads();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();
@ -555,7 +556,7 @@ fn keys(c: &mut Criterion) {
/// [`DatabaseRo::values`]
#[named]
fn values(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env_all_threads();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut table = env_inner.open_db_rw::<Outputs>(&tx_rw).unwrap();

View file

@ -1,4 +1,4 @@
//! TODO
//! `trait {Env, EnvInner, TxR{o,w}, Tables[Mut]}` benchmarks.
//---------------------------------------------------------------------------------------------------- Import
use criterion::{black_box, criterion_group, criterion_main, Criterion};
@ -12,7 +12,7 @@ use cuprate_database::{
ConcreteEnv, Env, EnvInner, TxRo, TxRw,
};
use cuprate_database_benchmark::tmp_concrete_env;
use cuprate_database_benchmark::tmp_env;
//---------------------------------------------------------------------------------------------------- Criterion
criterion_group! {
@ -46,7 +46,7 @@ fn open(c: &mut Criterion) {
/// [`Env::env_inner`].
#[named]
fn env_inner(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env();
c.bench_function(function_name!(), |b| {
b.iter(|| {
@ -58,7 +58,7 @@ fn env_inner(c: &mut Criterion) {
/// Create and commit read-only transactions.
#[named]
fn tx_ro(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env();
let env_inner = env.env_inner();
c.bench_function(function_name!(), |b| {
@ -72,7 +72,7 @@ fn tx_ro(c: &mut Criterion) {
/// Create and commit read/write transactions.
#[named]
fn tx_rw(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env();
let env_inner = env.env_inner();
c.bench_function(function_name!(), |b| {
@ -86,7 +86,7 @@ fn tx_rw(c: &mut Criterion) {
/// Open all database tables in read-only mode.
#[named]
fn open_tables(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env();
let env_inner = env.env_inner();
let tx_ro = env_inner.tx_ro().unwrap();
@ -102,7 +102,7 @@ fn open_tables(c: &mut Criterion) {
/// Open all database tables in read/write mode.
#[named]
fn open_tables_mut(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
@ -118,7 +118,7 @@ fn open_tables_mut(c: &mut Criterion) {
/// `Env` memory map resizes.
#[named]
fn resize(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env();
// Resize by the OS page size.
let page_size = page_size();
@ -136,7 +136,7 @@ fn resize(c: &mut Criterion) {
/// Access current memory map size of the database.
#[named]
fn current_map_size(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env();
c.bench_function(function_name!(), |b| {
b.iter(|| {
@ -151,7 +151,7 @@ fn current_map_size(c: &mut Criterion) {
/// Access on-disk size of the database.
#[named]
fn disk_size_bytes(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env();
c.bench_function(function_name!(), |b| {
b.iter(|| {

View file

@ -1,3 +1,4 @@
//! Same as `env.rs` but multi-threaded.
//! TODO: create multi-threaded benchmarks
//---------------------------------------------------------------------------------------------------- Import
@ -12,7 +13,7 @@ use cuprate_database::{
ConcreteEnv, Env, EnvInner, TxRo, TxRw,
};
use cuprate_database_benchmark::tmp_concrete_env;
use cuprate_database_benchmark::tmp_env_all_threads;
//---------------------------------------------------------------------------------------------------- Criterion
criterion_group! {
@ -46,7 +47,7 @@ fn open(c: &mut Criterion) {
/// [`Env::env_inner`].
#[named]
fn env_inner(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env_all_threads();
c.bench_function(function_name!(), |b| {
b.iter(|| {
@ -58,7 +59,7 @@ fn env_inner(c: &mut Criterion) {
/// Create and commit read-only transactions.
#[named]
fn tx_ro(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env_all_threads();
let env_inner = env.env_inner();
c.bench_function(function_name!(), |b| {
@ -72,7 +73,7 @@ fn tx_ro(c: &mut Criterion) {
/// Create and commit read/write transactions.
#[named]
fn tx_rw(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env_all_threads();
let env_inner = env.env_inner();
c.bench_function(function_name!(), |b| {
@ -86,7 +87,7 @@ fn tx_rw(c: &mut Criterion) {
/// Open all database tables in read-only mode.
#[named]
fn open_tables(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env_all_threads();
let env_inner = env.env_inner();
let tx_ro = env_inner.tx_ro().unwrap();
@ -102,7 +103,7 @@ fn open_tables(c: &mut Criterion) {
/// Open all database tables in read/write mode.
#[named]
fn open_tables_mut(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env_all_threads();
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
@ -118,7 +119,7 @@ fn open_tables_mut(c: &mut Criterion) {
/// `Env` memory map resizes.
#[named]
fn resize(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env_all_threads();
// Resize by the OS page size.
let page_size = page_size();
@ -136,7 +137,7 @@ fn resize(c: &mut Criterion) {
/// Access current memory map size of the database.
#[named]
fn current_map_size(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env_all_threads();
c.bench_function(function_name!(), |b| {
b.iter(|| {
@ -151,7 +152,7 @@ fn current_map_size(c: &mut Criterion) {
/// Access on-disk size of the database.
#[named]
fn disk_size_bytes(c: &mut Criterion) {
let (env, _tempdir) = tmp_concrete_env();
let (env, _tempdir) = tmp_env_all_threads();
c.bench_function(function_name!(), |b| {
b.iter(|| {

View file

@ -0,0 +1,25 @@
//! `cuprate_database::service` benchmarks.
//---------------------------------------------------------------------------------------------------- Import
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use function_name::named;
use cuprate_database::{
config::Config,
resize::{page_size, ResizeAlgorithm},
tables::Outputs,
ConcreteEnv, Env, EnvInner, TxRo, TxRw,
};
use cuprate_database_benchmark::tmp_env_all_threads;
//---------------------------------------------------------------------------------------------------- Criterion
criterion_group! {
benches,
}
criterion_main!(benches);
//---------------------------------------------------------------------------------------------------- Benchmarks
// TODO

View file

@ -1,4 +1,4 @@
//! TODO
//! `trait Storable` benchmarks.
//---------------------------------------------------------------------------------------------------- Import
use criterion::{black_box, criterion_group, criterion_main, Criterion};

View file

@ -11,10 +11,20 @@ use cuprate_database::{config::Config, ConcreteEnv, Env};
///
/// TODO: changing this to `-> impl Env` causes lifetime errors...
#[allow(clippy::missing_panics_doc)]
pub fn tmp_concrete_env() -> (ConcreteEnv, tempfile::TempDir) {
pub fn tmp_env() -> (ConcreteEnv, tempfile::TempDir) {
let tempdir = tempfile::tempdir().unwrap();
let config = Config::low_power(Some(tempdir.path().into()));
let env = ConcreteEnv::open(config).unwrap();
(env, tempdir)
}
/// Same as [`tmp_env`] but uses all system threads.
#[allow(clippy::missing_panics_doc)]
pub fn tmp_env_all_threads() -> (ConcreteEnv, tempfile::TempDir) {
let tempdir = tempfile::tempdir().unwrap();
let config = Config::fast(Some(tempdir.path().into()));
let env = ConcreteEnv::open(config).unwrap();
(env, tempdir)
}

View file

@ -80,4 +80,4 @@
#![cfg_attr(debug_assertions, allow(clippy::todo, clippy::multiple_crate_versions))]
mod helper;
pub use helper::tmp_concrete_env;
pub use helper::{tmp_env, tmp_env_all_threads};