loro/crates/fractional_index/examples/size.rs
Zixuan Chen 54637a7b42
Publish v0.16.2 to crates.io (#374)
* chore: mark dev-utils not published

* chore: release rust crates

* chore: publish fi

* chore: pre publish fi

* chore: update lockfile

* test: change fuzz rev
2024-05-29 22:55:55 +08:00

27 lines
839 B
Rust

use loro_fractional_index::FractionalIndex;
fn find_common_prefix(a: &[u8], b: &[u8]) -> usize {
a.iter().zip(b.iter()).take_while(|(a, b)| a == b).count()
}
fn main() {
// jitter
let mut rng = rand::thread_rng();
let mut size = 0;
let mut compress_size = 0;
for jitter in 0..3 {
let mut n = FractionalIndex::jitter_default(&mut rng, jitter);
for _ in 0..10000 {
let new = FractionalIndex::new_before_jitter(&n, &mut rng, jitter);
assert!(new < n);
size += new.as_bytes().len();
compress_size +=
new.as_bytes().len() - find_common_prefix(new.as_bytes(), n.as_bytes()) + 1;
n = new;
}
println!(
"size = {} compress {} with jitter {}",
size, compress_size, jitter
);
}
}