changeset 78:bd48baf0722a

Add benchmark
author Lewin Bormann <lbo@spheniscida.de>
date Wed, 19 Feb 2020 16:01:33 +0100
parents 638c945c4d82
children 3aa929eb0772
files Cargo.toml README.md benches/sstable.rs src/lib.rs
diffstat 4 files changed, 89 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/Cargo.toml	Wed Feb 19 15:05:00 2020 +0100
+++ b/Cargo.toml	Wed Feb 19 16:01:33 2020 +0100
@@ -8,6 +8,7 @@
 authors = ["Lewin Bormann <lbo@spheniscida.de>"]
 license = "MIT"
 documentation = "https://docs.rs/sstable"
+edition = "2018"
 
 [dependencies]
 crc = "1.2"
@@ -16,6 +17,12 @@
 
 [dev-dependencies]
 time-test = "0.2"
+bencher = "0.1"
+rand = "0.7"
+
+[[bench]]
+name = "sstable"
+harness = false
 
 [workspace]
 members = ["examples/rw_sstable"]
--- a/README.md	Wed Feb 19 15:05:00 2020 +0100
+++ b/README.md	Wed Feb 19 16:01:33 2020 +0100
@@ -36,6 +36,23 @@
 Google's LevelDB in Rust. That's the reason for the code being a bit more
 complicated than needed at some points.
 
+## Performance
+
+With no compression on a tmpfs volume running on an idle `Intel(R) Xeon(R) CPU
+E5-1650 v2 @ 3.50GHz` processor, the benchmark shows that in tables of 10'000
+entries of each 16 key bytes and 16 value bytes, this crate will
+
+* read 5.3 million entries per second
+* write 1.2 million entries per second
+
+The performance for tables of different sizes may differ.
+
+## Corruption and errors
+
+Checksum verification failures often stem from either corruption (obviously)
+or incompletely written or half-overwritten SSTable files.
+
+
 ## Contribute
 
 Contributions are very welcome! Feel free to send pull requests.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/benches/sstable.rs	Wed Feb 19 16:01:33 2020 +0100
@@ -0,0 +1,65 @@
+#[macro_use]
+extern crate bencher;
+
+use std::fs;
+
+use bencher::Bencher;
+use rand::random;
+
+use sstable::{TableBuilder, TableIterator, Table, SSIterator};
+
+fn random_string(n: usize) -> String {
+    let mut v = vec![0; n];
+    for c in v.iter_mut() {
+        *c = random::<u8>() % 26 + 65;
+    }
+    String::from_utf8(v).unwrap()
+}
+
+fn write_tmp_table(entries: usize) {
+    let mut v = vec![(String::new(), String::new()); entries];
+    for i in 0..entries {
+        v[i] = (random_string(16), random_string(16));
+    }
+    v.sort();
+
+    let dst = fs::OpenOptions::new().create(true).write(true).open("/tmp/.sstabletestfile").unwrap();
+    let mut opt = sstable::Options::default();
+    let mut tb = TableBuilder::new(opt, dst);
+
+    for (k, v) in v {
+        tb.add(k.as_bytes(), v.as_bytes()).unwrap();
+    }
+    tb.finish().unwrap();
+}
+
+fn rm_tmp_table() {
+    fs::remove_file("/tmp/.sstabletestfile");
+}
+
+fn bench_write(b: &mut Bencher) {
+    let N = 100000;
+    b.iter(|| {
+        write_tmp_table(N);
+        rm_tmp_table();
+    });
+}
+
+fn bench_read(b: &mut Bencher) {
+    rm_tmp_table();
+    write_tmp_table(100000);
+    b.iter(|| {
+        let tbr = Table::new_from_file(sstable::Options::default(), std::path::Path::new("/tmp/.sstabletestfile")).unwrap();
+        let mut iter = tbr.iter();
+
+        let mut count = 0;
+        let mut entries = 0;
+        while let Some((k, v)) = iter.next() {
+            count += k.len() + v.len();
+            entries += 1;
+        }
+    });
+}
+
+benchmark_group!(benches, bench_write, bench_read);
+benchmark_main!(benches);
--- a/src/lib.rs	Wed Feb 19 15:05:00 2020 +0100
+++ b/src/lib.rs	Wed Feb 19 16:01:33 2020 +0100
@@ -26,5 +26,3 @@
 
 #[cfg(test)]
 mod test_util;
-#[cfg(test)]
-mod benchmark;