2022-10-27 08:36:04 +00:00
|
|
|
use criterion::{criterion_group, criterion_main, Criterion};
|
2022-10-31 08:16:44 +00:00
|
|
|
|
2022-11-14 02:49:42 +00:00
|
|
|
#[cfg(feature = "test_utils")]
|
2022-10-28 10:28:55 +00:00
|
|
|
mod run {
|
2022-10-31 08:16:44 +00:00
|
|
|
|
2022-10-28 10:28:55 +00:00
|
|
|
use super::*;
|
|
|
|
use arbitrary::Unstructured;
|
2022-12-27 06:18:46 +00:00
|
|
|
use bench_utils::TextAction;
|
2023-01-16 10:44:19 +00:00
|
|
|
use loro_internal::container::registry::ContainerWrapper;
|
|
|
|
use loro_internal::fuzz::test_multi_sites;
|
|
|
|
use loro_internal::fuzz::Action;
|
|
|
|
use loro_internal::LoroCore;
|
2022-10-28 10:28:55 +00:00
|
|
|
use rand::Rng;
|
|
|
|
use rand::SeedableRng;
|
2022-10-27 08:36:04 +00:00
|
|
|
|
2022-11-09 03:04:58 +00:00
|
|
|
pub fn two_client_edits(c: &mut Criterion) {
|
2022-10-28 10:28:55 +00:00
|
|
|
let mut rgn = rand::rngs::StdRng::seed_from_u64(0);
|
|
|
|
let mut bytes = Vec::new();
|
2022-11-10 01:30:52 +00:00
|
|
|
for _ in 0..8000 {
|
2022-10-28 10:28:55 +00:00
|
|
|
bytes.push(rgn.gen::<u8>());
|
|
|
|
}
|
2022-10-27 08:36:04 +00:00
|
|
|
|
2022-10-28 10:28:55 +00:00
|
|
|
let mut gen = Unstructured::new(&bytes);
|
2022-11-10 01:30:52 +00:00
|
|
|
let mut c = c.benchmark_group("sync");
|
2022-11-15 08:02:42 +00:00
|
|
|
let mut actions = gen.arbitrary::<[Action; 200]>().unwrap();
|
2022-10-28 10:28:55 +00:00
|
|
|
c.bench_function("random text edit 2 sites", |b| {
|
2022-11-15 08:02:42 +00:00
|
|
|
b.iter(|| test_multi_sites(2, &mut actions))
|
2022-10-28 10:28:55 +00:00
|
|
|
});
|
2022-11-09 03:04:58 +00:00
|
|
|
|
|
|
|
c.bench_function("random text edit 8 sites", |b| {
|
2022-11-15 08:02:42 +00:00
|
|
|
b.iter(|| test_multi_sites(8, &mut actions))
|
2022-11-09 03:04:58 +00:00
|
|
|
});
|
2022-11-15 08:02:42 +00:00
|
|
|
let mut actions = gen.arbitrary::<[Action; 4000]>().unwrap();
|
2022-11-10 01:30:52 +00:00
|
|
|
c.sample_size(10);
|
|
|
|
c.bench_function("random text edit 8 sites long", |b| {
|
2022-11-15 08:02:42 +00:00
|
|
|
b.iter(|| test_multi_sites(8, &mut actions))
|
2022-11-10 01:30:52 +00:00
|
|
|
});
|
2022-10-28 10:28:55 +00:00
|
|
|
}
|
2022-10-31 08:16:44 +00:00
|
|
|
|
|
|
|
pub fn b4(c: &mut Criterion) {
|
2022-12-27 06:18:46 +00:00
|
|
|
let actions = bench_utils::get_automerge_actions();
|
2022-11-18 13:16:29 +00:00
|
|
|
let mut b = c.benchmark_group("direct_apply");
|
2022-11-10 01:30:52 +00:00
|
|
|
b.bench_function("B4", |b| {
|
2022-10-31 08:16:44 +00:00
|
|
|
b.iter(|| {
|
|
|
|
let mut loro = LoroCore::default();
|
2022-11-11 07:23:22 +00:00
|
|
|
let text = loro.get_text("text");
|
|
|
|
text.with_container(|text| {
|
2022-12-27 06:18:46 +00:00
|
|
|
for TextAction { pos, ins, del } in actions.iter() {
|
2022-12-04 03:09:49 +00:00
|
|
|
text.delete(&loro, *pos, *del);
|
|
|
|
text.insert(&loro, *pos, ins);
|
2022-11-28 13:28:15 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
b.bench_function("B4 Observed", |b| {
|
|
|
|
b.iter(|| {
|
|
|
|
let mut loro = LoroCore::default();
|
|
|
|
loro.subscribe_deep(Box::new(|_| {}));
|
|
|
|
let text = loro.get_text("text");
|
|
|
|
text.with_container(|text| {
|
2022-12-27 06:18:46 +00:00
|
|
|
for TextAction { pos, ins, del } in actions.iter() {
|
2022-12-04 03:09:49 +00:00
|
|
|
text.delete(&loro, *pos, *del);
|
|
|
|
text.insert(&loro, *pos, ins);
|
2022-10-31 08:16:44 +00:00
|
|
|
}
|
2022-11-11 07:23:22 +00:00
|
|
|
})
|
2022-10-31 08:16:44 +00:00
|
|
|
})
|
|
|
|
});
|
2022-11-09 03:04:58 +00:00
|
|
|
|
|
|
|
b.sample_size(10);
|
2022-11-10 01:30:52 +00:00
|
|
|
b.bench_function("B4DirectSync", |b| {
|
2022-11-09 03:04:58 +00:00
|
|
|
b.iter(|| {
|
|
|
|
let mut loro = LoroCore::default();
|
|
|
|
let mut loro_b = LoroCore::default();
|
2022-12-27 06:18:46 +00:00
|
|
|
for TextAction { pos, ins, del } in actions.iter() {
|
2022-11-11 07:23:22 +00:00
|
|
|
let text = loro.get_text("text");
|
|
|
|
text.with_container(|text| {
|
2022-12-04 03:09:49 +00:00
|
|
|
text.delete(&loro, *pos, *del);
|
|
|
|
text.insert(&loro, *pos, ins);
|
2022-11-11 07:23:22 +00:00
|
|
|
});
|
2022-11-09 03:04:58 +00:00
|
|
|
|
2022-12-12 17:39:57 +00:00
|
|
|
loro_b.import(loro.export(loro_b.vv_cloned()));
|
2022-11-09 03:04:58 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
2022-11-09 13:41:32 +00:00
|
|
|
|
2022-11-10 01:30:52 +00:00
|
|
|
drop(b);
|
|
|
|
let mut b = c.benchmark_group("sync");
|
2022-11-09 13:41:32 +00:00
|
|
|
b.bench_function("B4Parallel", |b| {
|
|
|
|
b.iter(|| {
|
|
|
|
let mut loro = LoroCore::default();
|
|
|
|
let mut loro_b = LoroCore::default();
|
|
|
|
let mut i = 0;
|
2022-12-27 06:18:46 +00:00
|
|
|
for TextAction { pos, ins, del } in actions.iter() {
|
|
|
|
let pos = *pos;
|
|
|
|
let del = *del;
|
2022-11-09 13:41:32 +00:00
|
|
|
i += 1;
|
|
|
|
if i > 1000 {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-11-11 07:23:22 +00:00
|
|
|
let mut text = loro.get_text("text");
|
2022-12-27 06:18:46 +00:00
|
|
|
text.delete(&loro, pos, del).unwrap();
|
|
|
|
text.insert(&loro, pos, ins).unwrap();
|
2022-11-11 07:23:22 +00:00
|
|
|
let mut text = loro_b.get_text("text");
|
2022-12-27 06:18:46 +00:00
|
|
|
text.delete(&loro_b, pos, del).unwrap();
|
|
|
|
text.insert(&loro_b, pos, ins).unwrap();
|
2022-12-12 17:39:57 +00:00
|
|
|
loro_b.import(loro.export(loro_b.vv_cloned()));
|
|
|
|
loro.import(loro_b.export(loro.vv_cloned()));
|
2022-11-09 13:41:32 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
2022-10-31 08:16:44 +00:00
|
|
|
}
|
2022-10-27 08:36:04 +00:00
|
|
|
}
|
2022-10-28 10:28:55 +00:00
|
|
|
pub fn dumb(_c: &mut Criterion) {}
|
2022-10-27 08:36:04 +00:00
|
|
|
|
2022-11-14 02:49:42 +00:00
|
|
|
#[cfg(feature = "test_utils")]
|
2022-11-09 03:04:58 +00:00
|
|
|
criterion_group!(benches, run::two_client_edits, run::b4);
|
2022-11-14 02:49:42 +00:00
|
|
|
#[cfg(not(feature = "test_utils"))]
|
2022-10-28 10:28:55 +00:00
|
|
|
criterion_group!(benches, dumb);
|
2022-10-27 08:36:04 +00:00
|
|
|
criterion_main!(benches);
|