Skip to content

Commit

Permalink
test: wip benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-herlemont committed Sep 1, 2024
1 parent 62c103c commit bdbcf66
Show file tree
Hide file tree
Showing 5 changed files with 505 additions and 3 deletions.
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ once_cell = "1.19"
dinghy-test = "0.7.2"
itertools = "0.13"
include_dir = "0.7"
cc = "1.1.15"
rusqlite = { version = "0.32.1", features = ["bundled"] }
concat-idents = "1.1.5"

[features]
default = [ "upgrade_0_5_x", "upgrade_0_7_x" ]
Expand All @@ -54,5 +57,9 @@ upgrade_0_7_x = [ ]
name = "overhead_data_size"
harness = false

[[bench]]
name = "seconday_index"
harness = false

[build-dependencies]
skeptic = "0.13.7"
2 changes: 1 addition & 1 deletion benches/overhead_data_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ fn redb_remove(db: &redb::Database, x: u32) {

fn use_native_db_insert(db: &Database, data: Data) {
let rw = db.rw_transaction().unwrap();
rw.insert(data).unwrap();
rw.upsert(data).unwrap();
rw.commit().unwrap();
}

Expand Down
146 changes: 146 additions & 0 deletions benches/seconday_index.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
mod setup;
use rusqlite::TransactionBehavior;
use setup::*;

use criterion::{
black_box, criterion_group, criterion_main, measurement::WallTime, BenchmarkGroup, BenchmarkId,
Criterion,
};
use native_model::{native_model, Model};

fn bench_insert<T: Default + Item + native_db::ToInput>(c: &mut Criterion, item_name: &str) {
let mut group = c.benchmark_group(format!("insert_{}", item_name));
group.plot_config(
criterion::PlotConfiguration::default().summary_scale(criterion::AxisScale::Linear),
);
group.sampling_mode(criterion::SamplingMode::Flat);

group.bench_function(BenchmarkId::new("XT", "Sqlite"), |b| {
b.iter_custom(|iters| {
let sqlite = SqliteBenchDatabase::setup();
let start = std::time::Instant::now();
for i in 0..iters {
let mut item = T::default();
item.update_pk(i);
sqlite.insert(item);
}
start.elapsed()
});
});

group.bench_function(BenchmarkId::new("1T", "Sqlite"), |b| {
b.iter_custom(|iters| {
let sqlite = SqliteBenchDatabase::setup();
let sqlite = sqlite.db();
let start = std::time::Instant::now();
let mut sqlite = sqlite.borrow_mut();
let transaction = sqlite
.transaction_with_behavior(TransactionBehavior::Immediate)
.unwrap();
for i in 0..iters {
let mut item = T::default();
item.update_pk(i);
let binary = item.native_model_encode().unwrap();
transaction
.execute(&item.generate_sqlite_insert(), (binary,))
.unwrap();
}
transaction.commit().unwrap();
start.elapsed()
});
});

group.bench_function(BenchmarkId::new("XT", "Native DB"), |b| {
b.iter_custom(|iters| {
let native_db = NativeDBBenchDatabase::setup();
let mut counter = 0;
let start = std::time::Instant::now();
for _ in 0..iters {
counter += 1;
let mut item = T::default();
item.update_pk(counter);
native_db.insert(item);
}
start.elapsed()
});
});

group.bench_function(BenchmarkId::new("1T", "Native DB"), |b| {
b.iter_custom(|iters| {
let native_db = NativeDBBenchDatabase::setup();
let native_db = native_db.db();
let start = std::time::Instant::now();
let native_db = native_db.rw_transaction().unwrap();
for i in 0..iters {
let mut item = T::default();
item.update_pk(i);
native_db.insert(item).unwrap();
}
native_db.commit().unwrap();
start.elapsed()
});
});

group.bench_function(BenchmarkId::new("XT", "Redb"), |b| {
b.iter_custom(|iters| {
let redb = RedbBenchDatabase::setup();
let start = std::time::Instant::now();
for i in 0..iters {
let mut item = T::default();
item.update_pk(i);
redb.insert(item);
}
start.elapsed()
});
});

group.bench_function(BenchmarkId::new("1T", "Redb"), |b| {
b.iter_custom(|iters| {
let redb = RedbBenchDatabase::setup();
let redb = redb.db();
let start = std::time::Instant::now();
let rw = redb.begin_write().unwrap();
{
let mut table = rw.open_table(REDB_TABLE).unwrap();
for i in 0..iters {
let mut item = T::default();
item.update_pk(i);
let binary = item.native_model_encode().unwrap();
table.insert(item.get_pk(), binary).unwrap();
}
}
rw.commit().unwrap();
start.elapsed()
});
});
}


fn bench_select<T: Default + Item + native_db::ToInput + Clone>(c: &mut Criterion, item_name: &str) {
let mut group = c.benchmark_group(format!("select_{}", item_name));
group.plot_config(
criterion::PlotConfiguration::default().summary_scale(criterion::AxisScale::Linear),
);
group.sampling_mode(criterion::SamplingMode::Flat);

group.bench_function(BenchmarkId::new("XT", "Native DB"), |b| {
b.iter_custom(|iters| {
let native_db = NativeDBBenchDatabase::setup();
native_db.insert_bulk_random::<T>(100);
let start = std::time::Instant::now();
start.elapsed()
});
});
}

fn first_compare(c: &mut Criterion) {
bench_insert::<Item1SK_NUni_NOpt>(c, "1 SK no unique no optional");
bench_insert::<Item10SK_NUni_NOpt>(c, "10 SK no unique no optional");
bench_insert::<Item50SK_NUni_NOpt>(c, "50 SK no unique no optional");
bench_insert::<Item100SK_NUni_NOpt>(c, "100 SK no unique no optional");

//bench_select::<Item1SK_NUni_NOpt>(c, "1 SK no unique no optional");
}

criterion_group!(benches, first_compare);
criterion_main!(benches);
Loading

0 comments on commit bdbcf66

Please sign in to comment.