loro/crates/loro-internal/examples/encoding_refactored.rs

76 lines
2.4 KiB
Rust
Raw Normal View History

2023-07-17 15:18:18 +00:00
use bench_utils::TextAction;
use criterion::black_box;
2023-07-17 15:18:18 +00:00
use loro_internal::refactor::loro::LoroApp;
fn main() {
// let actions = bench_utils::get_automerge_actions();
// {
// let loro = LoroApp::default();
// let text = loro.get_text("text");
// let mut txn = loro.txn().unwrap();
// for TextAction { pos, ins, del } in actions.iter() {
// text.delete(&mut txn, *pos, *del);
// text.insert(&mut txn, *pos, ins);
// }
// txn.commit().unwrap();
// let snapshot = loro.export_snapshot();
// let updates = loro.export_from(&Default::default());
// println!("\n");
// println!("Snapshot size={}", snapshot.len());
// println!("Updates size={}", updates.len());
// println!("\n");
// loro.diagnose_size();
// }
// println!("\n");
// println!("\n");
// println!("\n");
// {
// println!("One Transaction Per Action");
// let loro = LoroApp::default();
// let text = loro.get_text("text");
// for TextAction { pos, ins, del } in actions.iter() {
// let mut txn = loro.txn().unwrap();
// text.delete(&mut txn, *pos, *del);
// text.insert(&mut txn, *pos, ins);
// txn.commit().unwrap();
// }
// let snapshot = loro.export_snapshot();
// let updates = loro.export_from(&Default::default());
// println!("\n");
// println!("Snapshot size={}", snapshot.len());
// println!("Updates size={}", updates.len());
// println!("\n");
// loro.diagnose_size();
// }
bench_decode();
}
fn bench_decode() {
2023-07-17 15:18:18 +00:00
let actions = bench_utils::get_automerge_actions();
{
let loro = LoroApp::default();
let text = loro.get_text("text");
let mut txn = loro.txn().unwrap();
let mut n = 0;
2023-07-17 15:18:18 +00:00
for TextAction { pos, ins, del } in actions.iter() {
if n % 10 == 0 {
drop(txn);
txn = loro.txn().unwrap();
}
n += 1;
2023-07-17 15:18:18 +00:00
text.delete(&mut txn, *pos, *del);
text.insert(&mut txn, *pos, ins);
}
txn.commit().unwrap();
let snapshot = loro.export_snapshot();
for _ in 0..100 {
let loro = LoroApp::new();
loro.import(black_box(&snapshot)).unwrap();
2023-07-17 15:18:18 +00:00
}
}
}