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

37 lines
1.4 KiB
Rust
Raw Normal View History

2023-02-17 01:52:14 +00:00
use bench_utils::{get_automerge_actions, TextAction};
use loro_internal::{log_store::EncodeConfig, LoroCore, VersionVector};
2023-02-17 01:55:57 +00:00
use rand::{rngs::StdRng, Rng, SeedableRng};
2023-02-17 01:52:14 +00:00
fn main() {
2023-02-17 01:55:57 +00:00
let mut rng: StdRng = SeedableRng::seed_from_u64(1);
2023-02-17 01:52:14 +00:00
let actions = get_automerge_actions();
2023-02-17 01:55:57 +00:00
let mut loro = LoroCore::new(Default::default(), Some(1));
let mut loro_b = LoroCore::new(Default::default(), Some(2));
2023-02-17 01:52:14 +00:00
let mut i = 0;
for TextAction { pos, ins, del } in actions.iter() {
i += 1;
if i > 1000 {
break;
}
let pos = *pos;
let del = *del;
let mut text = loro.get_text("text");
text.delete(&loro, pos, del).unwrap();
text.insert(&loro, pos, ins).unwrap();
let mut text = loro_b.get_text("text");
2023-02-17 01:55:57 +00:00
let r = rng.gen_range(1..11);
for _ in 0..r {
text.delete(&loro_b, pos, del).unwrap();
text.insert(&loro_b, pos, ins).unwrap();
}
2023-02-17 01:52:14 +00:00
loro_b.import(loro.export(loro_b.vv_cloned()));
loro.import(loro_b.export(loro.vv_cloned()));
}
2023-02-17 01:55:57 +00:00
let encoded =
loro.encode_with_cfg(EncodeConfig::rle_update(VersionVector::new()).without_compress());
println!("parallel doc size {} bytes", encoded.len());
let encoded = loro.encode_with_cfg(EncodeConfig::snapshot().without_compress());
2023-02-17 01:52:14 +00:00
println!("parallel doc size {} bytes", encoded.len());
}