-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62c103c
commit bdbcf66
Showing
5 changed files
with
505 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Oops, something went wrong.