loro/crates/loro-internal/examples/encoding_refactored.rs
Zixuan Chen 1e736df133
Refactor: rm legacy code (#97)
* refactor: rm legacy code

* chore: rm dead code

* refactor: mv refactored files outside

* refactor: rename files & methods

* chore: rm unused deps

* fix: compact bytes err

* chore: fix ci
2023-07-31 11:49:55 +08:00

101 lines
2.9 KiB
Rust

use bench_utils::TextAction;
use criterion::black_box;
use loro_internal::loro::LoroDoc;
fn main() {
log_size();
// bench_decode();
// bench_decode_updates();
}
#[allow(unused)]
fn log_size() {
let actions = bench_utils::get_automerge_actions();
{
let loro = LoroDoc::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 = LoroDoc::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();
}
}
#[allow(unused)]
fn bench_decode() {
let actions = bench_utils::get_automerge_actions();
{
let loro = LoroDoc::default();
let text = loro.get_text("text");
#[allow(warnings)]
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();
// for _ in 0..100 {
// black_box(loro.export_snapshot());
// }
for _ in 0..100 {
let loro = LoroDoc::new();
loro.import(black_box(&snapshot)).unwrap();
}
}
}
#[allow(unused)]
fn bench_decode_updates() {
let actions = bench_utils::get_automerge_actions();
let loro = LoroDoc::default();
let text = loro.get_text("text");
#[allow(warnings)]
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 updates = loro.export_from(&Default::default());
for _ in 0..10 {
let loro = LoroDoc::new();
loro.import(black_box(&updates)).unwrap();
}
}