loro/crates/loro-internal/benches/tree.rs

95 lines
3.3 KiB
Rust
Raw Normal View History

feat: movable tree support (#120) * feat: tree state * feat: tree value * feat: tree handler * fix: tree diff * test: fuzz tree * feat: tree snapshot * fix: tree default value * fix: test new node * fix: tree diff * fix: tree unresolved value * fix: tree fuzz * fix: tree fuzz move * fix: sort by tree id * fix: tree diff sorted by lamport * fix: sort roots before tree converted to string * fix: rebase main * fix: tree fuzz * fix: delete undo * fix: tree to json children sorted * fix: diff calculate * fix: diff cycle move * fix: tree old parent cache * feat: cache * fix: local op add tree cache * fix: don't add same tree move to cache * fix: need update cache * feat: new cache * bench: add checkout bench * chore: clean * fix: apply node uncheck * perf: lamport bound * fix: calc old parent * feat: tree wasm * fix: change tree diff * fix: tree diff retreat * fix: tree diff should not apply when add node * feat: new tree loro value * chore: typo * fix: tree deep value * fix: snapshot tree index -1 * fix: decode tree snapshot use state * fix: release state lock when emit event * fix: tree node meta container * fix: need set map container when covert to local tree op * fix: tree value add deleted * fix: more then one op in a change * fix: tree fuzz deleted equal * fix: tree calc min lamport * feat: tree encoding v2 * doc: movable tree * fix: test tree meta * test: remove import bytes check * refactor: diff of text and map * refactor: del span * perf: tree state use deleted cache * fix: some details * fix: loro js tree create * feat: add un exist tree node * bench: tree depth * fix: check out should emit event * refactor: event * fix: fuzz err * fix: pass all tests * fix: fuzz err * fix: list child cache err * chore: rm debug code * fix: encode enhanced err * fix: encode enchanced * fix: fix several richtext issue * fix: richtext anchor err * chore: rm debug code * fix: richtext fuzz err * feat: speedup text snapshot decode * perf: optimize snapshot encoding * perf: speed up decode & insert * fix: fugue span merge err * perf: speedup delete & id cursor map * fix: fugue merge err * chore: update utils * fix: fix merge * fix: return err apply op * fix: fix merge * fix: get map container as tree meta
2023-10-30 03:13:52 +00:00
use criterion::{criterion_group, criterion_main, Criterion};
#[cfg(feature = "test_utils")]
mod tree {
use super::*;
use loro_internal::LoroDoc;
use rand::{rngs::StdRng, Rng};
pub fn tree_move(c: &mut Criterion) {
let mut b = c.benchmark_group("movable tree");
b.sample_size(10);
b.bench_function("10^3 tree move 10^5", |b| {
let loro = LoroDoc::default();
let tree = loro.get_tree("tree");
let mut ids = vec![];
let size = 1000;
for _ in 0..size {
ids.push(loro.with_txn(|txn| tree.create(txn)).unwrap())
}
let mut rng: StdRng = rand::SeedableRng::seed_from_u64(0);
let n = 100000;
b.iter(|| {
let mut txn = loro.txn().unwrap();
for _ in 0..n {
let i = rng.gen::<usize>() % size;
let j = rng.gen::<usize>() % size;
tree.mov(&mut txn, ids[i], ids[j]).unwrap_or_default();
}
drop(txn)
})
});
b.bench_function("1000 node checkout 10^3", |b| {
let mut loro = LoroDoc::default();
let tree = loro.get_tree("tree");
let mut ids = vec![];
let mut versions = vec![];
let size = 1000;
for _ in 0..size {
ids.push(loro.with_txn(|txn| tree.create(txn)).unwrap())
}
let mut rng: StdRng = rand::SeedableRng::seed_from_u64(0);
let mut n = 1000;
while n > 0 {
let i = rng.gen::<usize>() % size;
let j = rng.gen::<usize>() % size;
if loro.with_txn(|txn| tree.mov(txn, ids[i], ids[j])).is_ok() {
versions.push(loro.oplog_frontiers());
n -= 1;
};
}
b.iter(|| {
for _ in 0..1000 {
let i = rng.gen::<usize>() % 1000;
let f = &versions[i];
loro.checkout(f).unwrap();
}
})
});
b.bench_function("300 deep node random checkout 10^3", |b| {
let depth = 300;
let mut loro = LoroDoc::default();
let tree = loro.get_tree("tree");
let mut ids = vec![];
let mut versions = vec![];
let id1 = loro.with_txn(|txn| tree.create(txn)).unwrap();
ids.push(id1);
versions.push(loro.oplog_frontiers());
for _ in 1..depth {
let id = loro
.with_txn(|txn| tree.create_and_mov(txn, *ids.last().unwrap()))
.unwrap();
ids.push(id);
versions.push(loro.oplog_frontiers());
}
let mut rng: StdRng = rand::SeedableRng::seed_from_u64(0);
b.iter(|| {
for _ in 0..1000 {
let i = rng.gen::<usize>() % depth;
let f = &versions[i];
loro.checkout(f).unwrap();
}
})
});
}
}
pub fn dumb(_c: &mut Criterion) {}
#[cfg(feature = "test_utils")]
criterion_group!(benches, tree::tree_move);
#[cfg(not(feature = "test_utils"))]
criterion_group!(benches, dumb);
criterion_main!(benches);