mirror of
https://github.com/loro-dev/loro.git
synced 2025-01-22 21:07:43 +00:00
test: add list containers bench
This commit is contained in:
parent
e4b7dc4806
commit
2a391b8797
3 changed files with 86 additions and 0 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -782,6 +782,7 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"arbitrary",
|
||||
"arbtest",
|
||||
"arref",
|
||||
"bit-vec",
|
||||
"color-backtrace",
|
||||
"colored",
|
||||
|
|
|
@ -29,6 +29,7 @@ wasm-bindgen = { version = "0.2.83", optional = true }
|
|||
js-sys = { version = "0.3.60", optional = true }
|
||||
serde_json = { version = "1.0.87", optional = true }
|
||||
columnar = { path = "../../../columnar/columnar" }
|
||||
arref = "0.1.0"
|
||||
|
||||
[dev-dependencies]
|
||||
serde_json = "1.0.87"
|
||||
|
@ -58,3 +59,7 @@ test_utils = ["crdt-list/fuzzing", "rand", "arbitrary", "tabled", "json"]
|
|||
[[bench]]
|
||||
name = "text"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "list"
|
||||
harness = false
|
||||
|
|
80
crates/loro-core/benches/list.rs
Normal file
80
crates/loro-core/benches/list.rs
Normal file
|
@ -0,0 +1,80 @@
|
|||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
#[cfg(feature = "test_utils")]
|
||||
mod run {
|
||||
use super::*;
|
||||
use arbitrary::Arbitrary;
|
||||
use arbitrary::Unstructured;
|
||||
use loro_core::LoroCore;
|
||||
use rand::Rng;
|
||||
use rand::SeedableRng;
|
||||
|
||||
pub fn many_list_containers(c: &mut Criterion) {
|
||||
#[derive(Arbitrary)]
|
||||
struct Action {
|
||||
container: u8,
|
||||
actor: u8,
|
||||
pos: u8,
|
||||
value: u8,
|
||||
sync: u8,
|
||||
}
|
||||
|
||||
let mut rgn = rand::rngs::StdRng::seed_from_u64(0);
|
||||
let mut bytes = Vec::new();
|
||||
for _ in 0..10000 {
|
||||
bytes.push(rgn.gen::<u8>());
|
||||
}
|
||||
|
||||
let mut gen = Unstructured::new(&bytes);
|
||||
let actions: [Action; 200] = gen.arbitrary().unwrap();
|
||||
let mut b = c.benchmark_group("10 list containers");
|
||||
b.sample_size(10);
|
||||
b.bench_function("sync random inserts to 10 list containers", |b| {
|
||||
b.iter(|| {
|
||||
let mut actors: Vec<_> = (0..10).map(|_| LoroCore::default()).collect();
|
||||
for action in actions.iter() {
|
||||
let len = actors.len();
|
||||
let actor = &mut actors[action.actor as usize % len];
|
||||
let container = action.container % 10;
|
||||
if container % 2 == 0 {
|
||||
let mut text = actor.get_text(container.to_string().as_str());
|
||||
text.insert(
|
||||
actor,
|
||||
(action.pos as usize) % text.text_len().max(1),
|
||||
action.value.to_string().as_str(),
|
||||
);
|
||||
} else {
|
||||
let mut list = actor.get_list(container.to_string().as_str());
|
||||
list.insert(
|
||||
actor,
|
||||
(action.pos as usize) % list.values_len().max(1),
|
||||
action.value.to_string().as_str(),
|
||||
);
|
||||
}
|
||||
|
||||
let a = (action.actor as usize) % len;
|
||||
let b = (action.sync as usize) % len;
|
||||
if a != b {
|
||||
let (a, b) = arref::array_mut_ref!(&mut actors, [a, b]);
|
||||
a.import(b.export(a.vv()));
|
||||
}
|
||||
}
|
||||
|
||||
for i in 1..actors.len() {
|
||||
let (a, b) = arref::array_mut_ref!(&mut actors, [0, i]);
|
||||
a.import(b.export(a.vv()));
|
||||
}
|
||||
for i in 1..actors.len() {
|
||||
let (a, b) = arref::array_mut_ref!(&mut actors, [i, 0]);
|
||||
a.import(b.export(a.vv()));
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
pub fn dumb(_c: &mut Criterion) {}
|
||||
|
||||
#[cfg(feature = "test_utils")]
|
||||
criterion_group!(benches, run::many_list_containers);
|
||||
#[cfg(not(feature = "test_utils"))]
|
||||
criterion_group!(benches, dumb);
|
||||
criterion_main!(benches);
|
Loading…
Reference in a new issue