add ledb read/write benches
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
cf591198a0
commit
e521e39f5e
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -176,6 +176,8 @@ dependencies = [
|
|||||||
"ledb-derive",
|
"ledb-derive",
|
||||||
"ledb-types",
|
"ledb-types",
|
||||||
"rand",
|
"rand",
|
||||||
|
"serde",
|
||||||
|
"serde_derive",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"zip",
|
"zip",
|
||||||
|
@ -25,3 +25,5 @@ bincode = "^2.0.0-rc.2"
|
|||||||
ledb = {git = "https://github.com/b4tman/ledb.git", rev="a646b90e", package="ledb"}
|
ledb = {git = "https://github.com/b4tman/ledb.git", rev="a646b90e", package="ledb"}
|
||||||
ledb-derive = {git = "https://github.com/b4tman/ledb.git", rev="a646b90e", package="ledb-derive"}
|
ledb-derive = {git = "https://github.com/b4tman/ledb.git", rev="a646b90e", package="ledb-derive"}
|
||||||
ledb-types = {git = "https://github.com/b4tman/ledb.git", rev="a646b90e", package="ledb-types"}
|
ledb-types = {git = "https://github.com/b4tman/ledb.git", rev="a646b90e", package="ledb-types"}
|
||||||
|
serde="1.0"
|
||||||
|
serde_derive="1.0"
|
||||||
|
@ -1,7 +1,13 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate criterion;
|
extern crate criterion;
|
||||||
extern crate bincode;
|
extern crate bincode;
|
||||||
|
extern crate ledb;
|
||||||
|
extern crate ledb_types;
|
||||||
|
extern crate serde;
|
||||||
|
extern crate serde_derive;
|
||||||
extern crate tempfile;
|
extern crate tempfile;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate serde_json;
|
||||||
|
|
||||||
use chgk_ledb_lib::db;
|
use chgk_ledb_lib::db;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
@ -11,9 +17,26 @@ use db::{Reader, Writer, WriterOpts};
|
|||||||
use criterion::{BatchSize, Criterion};
|
use criterion::{BatchSize, Criterion};
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
|
|
||||||
#[derive(bincode::Encode, bincode::Decode, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
use ledb::{Document, Options, Storage};
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(
|
||||||
|
bincode::Encode,
|
||||||
|
bincode::Decode,
|
||||||
|
Clone,
|
||||||
|
Debug,
|
||||||
|
PartialEq,
|
||||||
|
Eq,
|
||||||
|
PartialOrd,
|
||||||
|
Ord,
|
||||||
|
Serialize,
|
||||||
|
Deserialize,
|
||||||
|
Document,
|
||||||
|
)]
|
||||||
struct TestData {
|
struct TestData {
|
||||||
num: u128,
|
#[document(primary)]
|
||||||
|
num1: u64,
|
||||||
|
num2: u64,
|
||||||
test: String,
|
test: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,9 +45,10 @@ const N: usize = 4096;
|
|||||||
fn gen_data(count: usize) -> impl Iterator<Item = TestData> {
|
fn gen_data(count: usize) -> impl Iterator<Item = TestData> {
|
||||||
(0..count)
|
(0..count)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|i| 143 + i as u128)
|
.map(|i| 143 + i as u64)
|
||||||
.map(|i| TestData {
|
.map(|i| TestData {
|
||||||
num: i,
|
num1: i,
|
||||||
|
num2: i*100 ^ 0xDF0E441122334455,
|
||||||
test: "test ---- Test ____".repeat(123 + i as usize % 15),
|
test: "test ---- Test ____".repeat(123 + i as usize % 15),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -85,9 +109,83 @@ fn db_write(c: &mut Criterion) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn ledb_write(c: &mut Criterion) {
|
||||||
|
let dir = tempdir().expect("tempdir");
|
||||||
|
let tmp_dir = dir.as_ref();
|
||||||
|
c.bench_function("ledb_write", |b| {
|
||||||
|
b.iter_batched(
|
||||||
|
|| {
|
||||||
|
let src = gen_data(N).collect::<Vec<TestData>>().into_iter();
|
||||||
|
let options: Options = serde_json::from_value(json!({
|
||||||
|
"map_size": 100 * 1024 * 1024, // 100mb
|
||||||
|
"write_map": true,
|
||||||
|
"map_async": true,
|
||||||
|
"no_lock": true,
|
||||||
|
"no_meta_sync": true,
|
||||||
|
"no_sync": true,
|
||||||
|
}))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let storage = Storage::new(tmp_dir, options).unwrap();
|
||||||
|
let collection = storage.collection("test").unwrap();
|
||||||
|
(src, collection)
|
||||||
|
},
|
||||||
|
|(src, collection)| collection.load(src).expect("load"),
|
||||||
|
BatchSize::SmallInput,
|
||||||
|
)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ledb_read(c: &mut Criterion) {
|
||||||
|
let dir = tempdir().expect("tempdir");
|
||||||
|
let tmp_dir = dir.as_ref();
|
||||||
|
|
||||||
|
let write_options: Options = serde_json::from_value(json!({
|
||||||
|
"map_size": 100 * 1024 * 1024, // 100mb
|
||||||
|
"write_map": true,
|
||||||
|
"map_async": true,
|
||||||
|
"no_lock": true,
|
||||||
|
"no_meta_sync": true,
|
||||||
|
"no_sync": true,
|
||||||
|
}))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let storage = Storage::new(&tmp_dir, write_options).unwrap();
|
||||||
|
let collection = storage.collection("test").unwrap();
|
||||||
|
let items_iter = gen_data(N).collect::<Vec<TestData>>().into_iter();
|
||||||
|
collection.load(items_iter).expect("load");
|
||||||
|
drop(collection);
|
||||||
|
drop(storage);
|
||||||
|
|
||||||
|
c.bench_function("ledb_read", |b| {
|
||||||
|
b.iter_batched(
|
||||||
|
|| {
|
||||||
|
let options: Options = serde_json::from_value(json!({
|
||||||
|
"read_only": true,
|
||||||
|
"map_async": true,
|
||||||
|
"no_lock": true,
|
||||||
|
}))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let storage = Storage::new(tmp_dir, options).unwrap();
|
||||||
|
let collection = storage.collection("test").unwrap();
|
||||||
|
collection
|
||||||
|
},
|
||||||
|
|collection| {
|
||||||
|
let mut collection_iter = collection.dump::<TestData>().expect("dump");
|
||||||
|
while let Some(item) = collection_iter.next() {
|
||||||
|
drop(item);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
BatchSize::SmallInput,
|
||||||
|
)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
fn config() -> Criterion {
|
fn config() -> Criterion {
|
||||||
Criterion::default().sample_size(40)
|
Criterion::default().sample_size(40)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
criterion_group! {name=ledb; config = config(); targets = ledb_read, ledb_write}
|
||||||
criterion_group! {name=benches; config = config(); targets = db_read, db_write}
|
criterion_group! {name=benches; config = config(); targets = db_read, db_write}
|
||||||
criterion_main!(benches);
|
criterion_main!(benches, ledb);
|
||||||
|
Loading…
Reference in New Issue
Block a user