loro/crates/loro-internal/examples/automerge_x100.rs
Zixuan Chen 17571ab6e0
Add size benchmark example (#276)
* test: add size bench example

* chore: update lock file
2024-02-28 21:59:20 +08:00

30 lines
940 B
Rust

use loro_internal::LoroDoc;
fn main() {
use bench_utils::TextAction;
use std::time::Instant;
let actions = bench_utils::get_automerge_actions();
let loro = LoroDoc::default();
let start = Instant::now();
// loro.subscribe_deep(Box::new(|_| ()));
let text = loro.get_text("text");
let n = 100;
for _ in 0..n {
let mut txn = loro.txn().unwrap();
for TextAction { del, ins, pos } in actions.iter() {
text.delete_with_txn(&mut txn, *pos, *del).unwrap();
text.insert_with_txn(&mut txn, *pos, ins).unwrap();
}
}
println!("Apply time {}", start.elapsed().as_millis());
loro.diagnose_size();
drop(actions);
let start = Instant::now();
let mut size = 0;
for _ in 0..1 {
size = loro.export_snapshot().len();
}
println!("Snapshot encoding time {}", start.elapsed().as_millis());
println!("Snapshot size {}", size);
}