chore: real time

This commit is contained in:
leeeon233 2023-02-20 22:01:40 +08:00
parent 037d17cd08
commit 0328c11a8e
2 changed files with 31 additions and 1 deletions

1
.gitignore vendored
View file

@ -4,3 +4,4 @@
flamegraph.svg flamegraph.svg
target target
dhat-heap.json dhat-heap.json
.DS_Store

View file

@ -2,7 +2,7 @@ use bench_utils::{get_automerge_actions, TextAction};
use loro_internal::{log_store::EncodeConfig, LoroCore, VersionVector}; use loro_internal::{log_store::EncodeConfig, LoroCore, VersionVector};
use rand::{rngs::StdRng, Rng, SeedableRng}; use rand::{rngs::StdRng, Rng, SeedableRng};
fn main() { fn parallel() {
let mut rng: StdRng = SeedableRng::seed_from_u64(1); let mut rng: StdRng = SeedableRng::seed_from_u64(1);
let actions = get_automerge_actions(); let actions = get_automerge_actions();
@ -34,3 +34,32 @@ fn main() {
let encoded = loro.encode_with_cfg(EncodeConfig::snapshot().without_compress()); let encoded = loro.encode_with_cfg(EncodeConfig::snapshot().without_compress());
println!("parallel doc size {} bytes", encoded.len()); 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()
}