2024-10-09 02:22:17 +00:00
|
|
|
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
|
|
|
use loro::{LoroDoc, LoroText};
|
2024-10-08 09:24:08 +00:00
|
|
|
|
|
|
|
fn bench_fork(c: &mut Criterion) {
|
2024-10-09 02:22:17 +00:00
|
|
|
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());
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
2024-10-08 09:24:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
criterion_group!(benches, bench_fork);
|
|
|
|
criterion_main!(benches);
|