2023-08-28 08:16:40 +00:00
|
|
|
use bench_utils::TextAction;
|
|
|
|
use loro_internal::LoroDoc;
|
2022-11-14 10:42:16 +00:00
|
|
|
|
|
|
|
fn main() {
|
2023-08-28 08:16:40 +00:00
|
|
|
let actions = bench_utils::get_automerge_actions();
|
2023-11-03 13:40:34 +00:00
|
|
|
|
2023-11-08 06:18:01 +00:00
|
|
|
// let loro = LoroDoc::default();
|
|
|
|
// let loro_b = LoroDoc::default();
|
|
|
|
// let text = loro.get_text("text");
|
|
|
|
// let mut i = 0;
|
|
|
|
// let start = Instant::now();
|
|
|
|
// for TextAction { pos, ins, del } in actions.iter() {
|
|
|
|
// {
|
|
|
|
// let mut txn = loro.txn().unwrap();
|
|
|
|
// text.delete(&mut txn, *pos, *del).unwrap();
|
|
|
|
// text.insert(&mut txn, *pos, ins).unwrap();
|
|
|
|
// }
|
|
|
|
|
|
|
|
// loro_b
|
|
|
|
// .import(&loro.export_from(&loro_b.oplog_vv()))
|
|
|
|
// .unwrap();
|
|
|
|
// i += 1;
|
|
|
|
// if i == 30000 {
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// println!("{}ms", start.elapsed().as_millis());
|
|
|
|
|
2023-08-28 08:16:40 +00:00
|
|
|
let loro = LoroDoc::default();
|
|
|
|
let text = loro.get_text("text");
|
2023-11-08 06:18:01 +00:00
|
|
|
|
2023-08-28 08:16:40 +00:00
|
|
|
for TextAction { pos, ins, del } in actions.iter() {
|
2023-11-08 06:18:01 +00:00
|
|
|
let mut txn = loro.txn().unwrap();
|
2023-11-28 08:22:43 +00:00
|
|
|
text.delete_with_txn(&mut txn, *pos, *del).unwrap();
|
|
|
|
text.insert_with_txn(&mut txn, *pos, ins).unwrap();
|
2023-11-08 06:18:01 +00:00
|
|
|
txn.commit().unwrap();
|
2023-08-28 08:16:40 +00:00
|
|
|
}
|
|
|
|
|
2023-11-08 06:18:01 +00:00
|
|
|
let snapshot = loro.export_snapshot();
|
|
|
|
let output = miniz_oxide::deflate::compress_to_vec(&snapshot, 6);
|
|
|
|
println!(
|
|
|
|
"snapshot size {} after compression {}",
|
|
|
|
snapshot.len(),
|
|
|
|
output.len()
|
|
|
|
);
|
2023-08-29 09:15:41 +00:00
|
|
|
|
2023-11-03 13:40:34 +00:00
|
|
|
// {
|
|
|
|
// // Delta encoding
|
2023-10-29 06:02:13 +00:00
|
|
|
|
2023-11-03 13:40:34 +00:00
|
|
|
// // let start = Instant::now();
|
|
|
|
// // for _ in 0..10 {
|
|
|
|
// // loro.export_from(&Default::default());
|
|
|
|
// // }
|
2023-08-29 09:15:41 +00:00
|
|
|
|
2023-11-03 13:40:34 +00:00
|
|
|
// // println!("Avg encode {}ms", start.elapsed().as_millis() as f64 / 10.0);
|
|
|
|
|
|
|
|
// let data = loro.export_from(&Default::default());
|
|
|
|
// let start = Instant::now();
|
|
|
|
// for _ in 0..5 {
|
|
|
|
// let b = LoroDoc::default();
|
|
|
|
// b.import(&data).unwrap();
|
|
|
|
// }
|
|
|
|
|
|
|
|
// println!("Avg decode {}ms", start.elapsed().as_millis() as f64 / 10.0);
|
|
|
|
// println!("size len={}", data.len());
|
|
|
|
// let d = miniz_oxide::deflate::compress_to_vec(&data, 10);
|
|
|
|
// println!("size after compress len={}", d.len());
|
|
|
|
// }
|
|
|
|
|
|
|
|
// {
|
|
|
|
// // Snapshot encoding
|
|
|
|
// // println!("\n=======================\nSnapshot Encoding:");
|
|
|
|
|
|
|
|
// // let start = Instant::now();
|
|
|
|
// // for _ in 0..10 {
|
|
|
|
// // loro.export_snapshot();
|
|
|
|
// // }
|
|
|
|
|
|
|
|
// // println!("Avg encode {}ms", start.elapsed().as_millis() as f64 / 10.0);
|
|
|
|
|
|
|
|
// // let data = loro.export_snapshot();
|
|
|
|
// // let start = Instant::now();
|
|
|
|
// // let times = 300;
|
|
|
|
// // for _ in 0..times {
|
|
|
|
// // let b = LoroDoc::default();
|
|
|
|
// // b.import(&data).unwrap();
|
|
|
|
// // }
|
|
|
|
|
|
|
|
// // println!(
|
|
|
|
// // "Avg decode {}ms",
|
|
|
|
// // start.elapsed().as_millis() as f64 / times as f64
|
|
|
|
// // );
|
|
|
|
// // println!("size len={}", data.len());
|
|
|
|
// // let d = miniz_oxide::deflate::compress_to_vec(&data, 10);
|
|
|
|
// // println!("size after compress len={}", d.len());
|
|
|
|
// }
|
2022-11-14 10:42:16 +00:00
|
|
|
}
|