use std::time::Instant;
use zebo::Zebo;
#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
struct DocumentId(u64);
impl zebo::DocumentId for DocumentId {
fn as_u64(&self) -> u64 {
self.0
}
fn from_u64(id: u64) -> Self {
DocumentId(id)
}
}
static ZERO: &[u8] = b"\0";
#[derive(Clone)]
struct Document {
id: String,
data: String,
}
impl zebo::Document for Document {
fn as_bytes(&self, v: &mut Vec<u8>) {
v.extend(self.id.as_bytes());
v.extend(ZERO);
v.extend(self.data.as_bytes());
}
fn len(&self) -> usize {
self.id.len() + 1 + self.data.len()
}
}
static PAGE_SIZE: u64 = 1024 * 5;
fn main() {
const MAX_DOC_PER_PAGE: u32 = 100000;
const LEN: usize = 64_000;
let docs: Vec<_> = (0..LEN)
.map(|i| {
(
DocumentId(1),
Document {
id: format!("Document {i}"),
data: format!("This is the content of document {i}."),
},
)
})
.collect();
println!("Run single");
let data_dir = "./zebo_data_dir_perf";
let _ = std::fs::remove_dir_all(data_dir);
std::fs::create_dir_all(data_dir).unwrap();
let mut zebo = Zebo::<MAX_DOC_PER_PAGE, PAGE_SIZE, DocumentId>::try_new(data_dir)
.expect("Failed to create Zebo instance");
let start = Instant::now();
zebo.reserve_space_for(&docs)
.expect("Failed to add documents")
.write_all()
.expect("Failed to write all documents");
println!("Elapsed {:?}", start.elapsed());
drop(zebo);
}