}
#[test]
fn lmdb_uuid() {
use lmdb_rs::*;
env_logger::try_init().unwrap_or(());
for i in 1..8 {
let n = i * 1_000_000;
std::fs::remove_dir_all("/tmp/sanakirja0").unwrap_or(());
std::fs::create_dir_all("/tmp/sanakirja0").unwrap();
let env = Env::new("/tmp/sanakirja0", 409_600_000, 2).unwrap();
let mut txn = Env::mut_txn_begin(&env).unwrap();
let mut db =
create_db_::<MutTxn<&Env, ()>, uuid::Bytes, u64, P<uuid::Bytes, u64>>(&mut txn)
.unwrap();
let mut times = [0f64; 4];
let mut test = Vec::with_capacity(n);
for i in 0..n {
let uuid = uuid::Uuid::new_v4();
test.push((uuid, i))
}
let now = std::time::SystemTime::now();
for (k, v) in test.iter() {
assert!(put(&mut txn, &mut db, k.as_bytes(), &(*v as u64)).unwrap());
}
times[0] = now.elapsed().unwrap().as_secs_f64();
let now = std::time::SystemTime::now();
for (k, v) in test.iter() {
assert_eq!(
btree::get(&txn, &db, k.as_bytes(), None).unwrap(),
Some((k.as_bytes(), &(*v as u64)))
)
}
times[1] = now.elapsed().unwrap().as_secs_f64();
std::fs::remove_dir_all("/tmp/test-lmdb").unwrap_or(());
std::fs::create_dir_all("/tmp/test-lmdb").unwrap_or(());
let env = EnvBuilder::new()
.map_size(1 << 30)
.open("/tmp/test-lmdb", 0o777)
.unwrap();
let db_handle = env.get_default_db(lmdb_rs::DbFlags::empty()).unwrap();
let txn = env.new_transaction().unwrap();
{
let db = txn.bind(&db_handle);
let now = std::time::SystemTime::now();
for (k, v) in test.iter() {
let k = lmdb_rs::MDB_val {
mv_size: 16,
mv_data: k.as_bytes().as_ptr() as *const libc::c_void,
};
db.set(&k, &(*v as u64)).unwrap();
}
times[2] = now.elapsed().unwrap().as_secs_f64();
}
match txn.commit() {
Err(_) => panic!("failed to commit!"),
Ok(_) => (),
}
let reader = env.get_reader().unwrap();
let db = reader.bind(&db_handle);
let now = std::time::SystemTime::now();
for (k, v) in test.iter() {
let k = lmdb_rs::MDB_val {
mv_size: 16,
mv_data: k.as_bytes().as_ptr() as *const libc::c_void,
};
let name = db.get::<u64>(&k).ok();
assert_eq!(name, Some(*v as u64))
}
times[3] = now.elapsed().unwrap().as_secs_f64();
print!("{}", n);
for t in times.iter() {
print!(", {}", t)
}
println!();
}