2023-07-17 15:18:18 +00:00
|
|
|
use bench_utils::TextAction;
|
2023-07-17 17:23:49 +00:00
|
|
|
use criterion::black_box;
|
2024-09-24 03:16:59 +00:00
|
|
|
use loro_internal::LoroDoc;
|
2023-07-17 15:18:18 +00:00
|
|
|
|
|
|
|
fn main() {
|
2024-06-07 05:18:30 +00:00
|
|
|
log_size();
|
|
|
|
// bench_decode();
|
2023-07-19 04:31:49 +00:00
|
|
|
// bench_decode_updates();
|
2023-07-18 06:39:17 +00:00
|
|
|
}
|
2023-07-17 17:23:49 +00:00
|
|
|
|
2023-07-19 04:31:49 +00:00
|
|
|
#[allow(unused)]
|
2023-07-18 06:39:17 +00:00
|
|
|
fn log_size() {
|
|
|
|
let actions = bench_utils::get_automerge_actions();
|
|
|
|
{
|
2023-07-19 13:21:37 +00:00
|
|
|
let loro = LoroDoc::default();
|
2023-07-18 06:39:17 +00:00
|
|
|
let text = loro.get_text("text");
|
|
|
|
let mut txn = loro.txn().unwrap();
|
2023-07-17 17:23:49 +00:00
|
|
|
|
2023-07-18 06:39:17 +00:00
|
|
|
for TextAction { pos, ins, del } in actions.iter() {
|
2023-11-28 08:22:43 +00:00
|
|
|
text.delete_with_txn(&mut txn, *pos, *del);
|
|
|
|
text.insert_with_txn(&mut txn, *pos, ins);
|
2023-07-18 06:39:17 +00:00
|
|
|
}
|
|
|
|
txn.commit().unwrap();
|
2024-10-02 03:11:08 +00:00
|
|
|
let snapshot = loro.export_snapshot().unwrap();
|
2023-07-18 06:39:17 +00:00
|
|
|
let updates = loro.export_from(&Default::default());
|
2025-01-04 17:25:15 +00:00
|
|
|
let json_updates = serde_json::to_string(&loro.export_json_updates(
|
|
|
|
&Default::default(),
|
|
|
|
&loro.oplog_vv(),
|
|
|
|
true,
|
|
|
|
))
|
|
|
|
.unwrap();
|
2023-07-18 06:39:17 +00:00
|
|
|
println!("\n");
|
|
|
|
println!("Snapshot size={}", snapshot.len());
|
|
|
|
println!("Updates size={}", updates.len());
|
2025-01-15 06:12:30 +00:00
|
|
|
println!("Json Updates size={}", json_updates.len());
|
2023-07-18 06:39:17 +00:00
|
|
|
println!("\n");
|
|
|
|
loro.diagnose_size();
|
|
|
|
}
|
|
|
|
println!("\n");
|
|
|
|
println!("\n");
|
|
|
|
println!("\n");
|
|
|
|
{
|
|
|
|
println!("One Transaction Per Action");
|
2023-07-19 13:21:37 +00:00
|
|
|
let loro = LoroDoc::default();
|
2023-07-18 06:39:17 +00:00
|
|
|
let text = loro.get_text("text");
|
|
|
|
|
|
|
|
for TextAction { pos, ins, del } in actions.iter() {
|
|
|
|
let mut txn = loro.txn().unwrap();
|
2023-11-28 08:22:43 +00:00
|
|
|
text.delete_with_txn(&mut txn, *pos, *del);
|
|
|
|
text.insert_with_txn(&mut txn, *pos, ins);
|
2023-07-18 06:39:17 +00:00
|
|
|
txn.commit().unwrap();
|
|
|
|
}
|
2024-10-02 03:11:08 +00:00
|
|
|
let snapshot = loro.export_snapshot().unwrap();
|
2023-07-18 06:39:17 +00:00
|
|
|
let updates = loro.export_from(&Default::default());
|
|
|
|
println!("\n");
|
|
|
|
println!("Snapshot size={}", snapshot.len());
|
|
|
|
println!("Updates size={}", updates.len());
|
|
|
|
println!("\n");
|
|
|
|
loro.diagnose_size();
|
|
|
|
}
|
2023-07-17 17:23:49 +00:00
|
|
|
}
|
|
|
|
|
2023-07-19 04:31:49 +00:00
|
|
|
#[allow(unused)]
|
2023-07-17 17:23:49 +00:00
|
|
|
fn bench_decode() {
|
2023-10-30 13:56:33 +00:00
|
|
|
println!("Bench decode");
|
2023-07-17 15:18:18 +00:00
|
|
|
let actions = bench_utils::get_automerge_actions();
|
|
|
|
{
|
2023-10-30 13:56:33 +00:00
|
|
|
let mut loro = LoroDoc::default();
|
2023-07-17 15:18:18 +00:00
|
|
|
let text = loro.get_text("text");
|
2023-10-30 13:56:33 +00:00
|
|
|
loro.start_auto_commit();
|
2023-07-17 15:18:18 +00:00
|
|
|
|
2023-10-30 13:56:33 +00:00
|
|
|
for _ in 0..10 {
|
|
|
|
for TextAction { pos, ins, del } in actions.iter() {
|
2023-11-28 08:22:43 +00:00
|
|
|
text.delete(*pos, *del);
|
|
|
|
text.insert(*pos, ins);
|
2023-10-30 13:56:33 +00:00
|
|
|
}
|
2023-07-17 15:18:18 +00:00
|
|
|
}
|
2024-10-02 03:11:08 +00:00
|
|
|
let snapshot = loro.export_snapshot().unwrap();
|
2023-07-19 04:31:49 +00:00
|
|
|
// for _ in 0..100 {
|
|
|
|
// black_box(loro.export_snapshot());
|
|
|
|
// }
|
2023-07-18 08:25:29 +00:00
|
|
|
|
2023-07-17 17:23:49 +00:00
|
|
|
for _ in 0..100 {
|
2023-07-19 13:21:37 +00:00
|
|
|
let loro = LoroDoc::new();
|
2023-07-17 17:23:49 +00:00
|
|
|
loro.import(black_box(&snapshot)).unwrap();
|
2023-07-17 15:18:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-07-19 04:31:49 +00:00
|
|
|
|
|
|
|
#[allow(unused)]
|
|
|
|
fn bench_decode_updates() {
|
|
|
|
let actions = bench_utils::get_automerge_actions();
|
2023-07-19 13:21:37 +00:00
|
|
|
let loro = LoroDoc::default();
|
2023-07-19 04:31:49 +00:00
|
|
|
let text = loro.get_text("text");
|
|
|
|
|
|
|
|
#[allow(warnings)]
|
|
|
|
for TextAction { pos, ins, del } in actions.iter() {
|
|
|
|
let mut txn = loro.txn().unwrap();
|
2023-11-28 08:22:43 +00:00
|
|
|
text.delete_with_txn(&mut txn, *pos, *del);
|
|
|
|
text.insert_with_txn(&mut txn, *pos, ins);
|
2023-07-19 04:31:49 +00:00
|
|
|
txn.commit().unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
let updates = loro.export_from(&Default::default());
|
|
|
|
for _ in 0..10 {
|
2023-07-19 13:21:37 +00:00
|
|
|
let loro = LoroDoc::new();
|
2023-07-19 04:31:49 +00:00
|
|
|
loro.import(black_box(&updates)).unwrap();
|
|
|
|
}
|
|
|
|
}
|