2023-12-05 03:57:41 +00:00
|
|
|
use criterion::{criterion_group, criterion_main, Criterion};
|
|
|
|
#[cfg(feature = "test_utils")]
|
|
|
|
mod event {
|
|
|
|
use super::*;
|
2024-05-20 22:14:49 +00:00
|
|
|
|
2023-12-05 03:57:41 +00:00
|
|
|
use loro_internal::{ListHandler, LoroDoc};
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
fn create_sub_container(handler: ListHandler, children_num: usize) -> Vec<ListHandler> {
|
|
|
|
let mut ans = vec![];
|
|
|
|
for idx in 0..children_num {
|
|
|
|
let child_handler = handler
|
2024-03-30 03:38:24 +00:00
|
|
|
.insert_container(idx, ListHandler::new_detached())
|
2023-12-05 03:57:41 +00:00
|
|
|
.unwrap();
|
|
|
|
ans.push(child_handler);
|
|
|
|
}
|
|
|
|
ans
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn resolved_container(c: &mut Criterion) {
|
|
|
|
let mut b = c.benchmark_group("resolved");
|
|
|
|
b.sample_size(10);
|
|
|
|
b.bench_function("subContainer in event", |b| {
|
|
|
|
let children_num = 80;
|
|
|
|
let deep = 3;
|
|
|
|
b.iter(|| {
|
2024-05-20 22:14:49 +00:00
|
|
|
let loro = LoroDoc::default();
|
2023-12-05 03:57:41 +00:00
|
|
|
loro.start_auto_commit();
|
2024-10-03 07:14:21 +00:00
|
|
|
let _g = loro.subscribe_root(Arc::new(|_e| {}));
|
2023-12-05 03:57:41 +00:00
|
|
|
let mut handlers = vec![loro.get_list("list")];
|
|
|
|
for _ in 0..deep {
|
|
|
|
handlers = handlers
|
|
|
|
.into_iter()
|
|
|
|
.flat_map(|h| create_sub_container(h, children_num))
|
|
|
|
.collect();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn dumb(_c: &mut Criterion) {}
|
|
|
|
|
|
|
|
#[cfg(feature = "test_utils")]
|
|
|
|
criterion_group!(benches, event::resolved_container);
|
|
|
|
#[cfg(not(feature = "test_utils"))]
|
|
|
|
criterion_group!(benches, dumb);
|
|
|
|
criterion_main!(benches);
|