diff --git a/.gitignore b/.gitignore index 1d4f5c1a..492f1bac 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ flamegraph.svg target dhat-heap.json +.DS_Store diff --git a/crates/loro-internal/examples/encoding_parallel.rs b/crates/loro-internal/examples/encoding_parallel.rs index 9504fe18..5d4326ae 100644 --- a/crates/loro-internal/examples/encoding_parallel.rs +++ b/crates/loro-internal/examples/encoding_parallel.rs @@ -2,7 +2,7 @@ use bench_utils::{get_automerge_actions, TextAction}; use loro_internal::{log_store::EncodeConfig, LoroCore, VersionVector}; use rand::{rngs::StdRng, Rng, SeedableRng}; -fn main() { +fn parallel() { let mut rng: StdRng = SeedableRng::seed_from_u64(1); let actions = get_automerge_actions(); @@ -34,3 +34,32 @@ fn main() { let encoded = loro.encode_with_cfg(EncodeConfig::snapshot().without_compress()); println!("parallel doc size {} bytes", encoded.len()); } + +fn real_time() { + let actions = get_automerge_actions(); + let mut c1 = LoroCore::new(Default::default(), Some(0)); + let mut c2 = LoroCore::new(Default::default(), Some(1)); + let mut t1 = c1.get_text("text"); + let mut t2 = c2.get_text("text"); + for (i, action) in actions.iter().enumerate() { + if i > 2000 { + break; + } + let TextAction { pos, ins, del } = action; + if i % 2 == 0 { + t1.delete(&c1, *pos, *del).unwrap(); + t1.insert(&c1, *pos, ins).unwrap(); + let update = c1.encode_with_cfg(EncodeConfig::update(c2.vv_cloned())); + c2.decode(&update).unwrap(); + } else { + t2.delete(&c2, *pos, *del).unwrap(); + t2.insert(&c2, *pos, ins).unwrap(); + let update = c2.encode_with_cfg(EncodeConfig::update(c1.vv_cloned())); + c1.decode(&update).unwrap(); + } + } +} + +fn main() { + real_time() +}