loro/crates/examples/benches/fork.rs
Zixuan Chen 59efca6fe5
perf: optimize kv export_all by reusing encoded block (#501)
* perf: optimize kv export_all by reusing encoded block

* chore: fix warnings

* perf: reuse encoded block bytes

* perf: optimize encode/decode speed further

* chore: fix warning
2024-10-09 10:22:17 +08:00

33 lines
1 KiB
Rust

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use loro::{LoroDoc, LoroText};
fn bench_fork(c: &mut Criterion) {
let mut b = c.benchmark_group("fork");
b.bench_function("fork with text edit at each fork", |b| {
let snapshot = {
let doc = LoroDoc::new();
let map = doc.get_map("map");
for i in 0..10000 {
let text = map
.insert_container(&i.to_string(), LoroText::new())
.unwrap();
text.insert(0, &i.to_string()).unwrap();
}
doc.export(loro::ExportMode::Snapshot).unwrap()
};
b.iter_with_setup(
|| {
let doc = LoroDoc::new();
doc.import(&snapshot).unwrap();
doc.get_text("text").insert(0, "123").unwrap();
doc
},
|doc| {
black_box(doc.fork());
},
);
});
}
criterion_group!(benches, bench_fork);
criterion_main!(benches);