diff options
Diffstat (limited to 'third_party/rust/lmdb-rkv/benches/utils.rs')
-rw-r--r-- | third_party/rust/lmdb-rkv/benches/utils.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/third_party/rust/lmdb-rkv/benches/utils.rs b/third_party/rust/lmdb-rkv/benches/utils.rs new file mode 100644 index 0000000000..0a240be591 --- /dev/null +++ b/third_party/rust/lmdb-rkv/benches/utils.rs @@ -0,0 +1,32 @@ +extern crate lmdb; +extern crate tempdir; + +use self::tempdir::TempDir; +use lmdb::{ + Environment, + Transaction, + WriteFlags, +}; + +pub fn get_key(n: u32) -> String { + format!("key{}", n) +} + +pub fn get_data(n: u32) -> String { + format!("data{}", n) +} + +pub fn setup_bench_db(num_rows: u32) -> (TempDir, Environment) { + let dir = TempDir::new("test").unwrap(); + let env = Environment::new().open(dir.path()).unwrap(); + + { + let db = env.open_db(None).unwrap(); + let mut txn = env.begin_rw_txn().unwrap(); + for i in 0..num_rows { + txn.put(db, &get_key(i), &get_data(i), WriteFlags::empty()).unwrap(); + } + txn.commit().unwrap(); + } + (dir, env) +} |