test: add more many_actors tests

This commit is contained in:
Zixuan Chen 2023-09-02 23:23:52 +08:00
parent 345b5bbcb9
commit 9be8cad562
No known key found for this signature in database
2 changed files with 80 additions and 18 deletions

View file

@ -7,6 +7,7 @@ mod run {
use super::*;
use bench_utils::TextAction;
use criterion::black_box;
use loro_common::LoroValue;
use loro_internal::loro::LoroDoc;
pub fn b4(c: &mut Criterion) {
@ -26,6 +27,38 @@ mod run {
})
});
b.bench_function("B4 with 100K actors history", |b| {
let store = LoroDoc::default();
for i in 0..100_000 {
store.set_peer_id(i);
let list = store.get_list("list");
let value: LoroValue = i.to_string().into();
let mut txn = store.txn().unwrap();
list.insert(&mut txn, 0, value).unwrap();
txn.commit().unwrap();
}
let update = store.export_snapshot();
drop(store);
b.iter_batched(
|| {
let loro = LoroDoc::default();
loro.import(&update).unwrap();
loro
},
|loro| {
let text = loro.get_text("text");
let mut txn = loro.txn().unwrap();
for TextAction { pos, ins, del } in actions.iter() {
text.delete(&mut txn, *pos, *del).unwrap();
text.insert(&mut txn, *pos, ins).unwrap();
}
},
criterion::BatchSize::SmallInput,
)
});
b.bench_function("B4 Obs", |b| {
b.iter(|| {
let loro = LoroDoc::default();

View file

@ -1,29 +1,58 @@
use std::time::Instant;
use std::{thread::spawn, time::Instant};
use loro_internal::{LoroDoc, LoroValue};
#[global_allocator]
static ALLOC: dhat::Alloc = dhat::Alloc;
// #[global_allocator]
// static ALLOC: dhat::Alloc = dhat::Alloc;
fn main() {
let mut actors: Vec<_> = (0..1000).map(|_| LoroDoc::default()).collect();
let mut updates: Vec<Vec<u8>> = Vec::new();
for (i, actor) in actors.iter_mut().enumerate() {
let list = actor.get_list("list");
with_100K_actors_then_action();
// import_with_many_actors();
}
fn import_with_many_actors() {
let store = LoroDoc::default();
for i in 0..10000 {
store.set_peer_id(i);
let list = store.get_list("list");
let value: LoroValue = i.to_string().into();
let mut txn = actor.txn().unwrap();
let mut txn = store.txn().unwrap();
list.insert(&mut txn, 0, value).unwrap();
txn.commit().unwrap();
updates.push(actor.export_from(&Default::default()));
}
drop(actors);
{
let start = Instant::now();
let bytes = store.export_snapshot();
LoroDoc::default().import(&bytes).unwrap();
println!("{} ms", start.elapsed().as_millis());
}
let profiler = dhat::Profiler::builder().trim_backtraces(None).build();
let start = Instant::now();
let mut actor = LoroDoc::default();
actor.import_batch(&updates).unwrap();
println!("{} bytes", updates.iter().map(|x| x.len()).sum::<usize>());
// dbg!(actor.get_state_deep_value());
println!("{} ms", start.elapsed().as_millis());
drop(profiler);
// let profiler = dhat::Profiler::builder().trim_backtraces(None).build();
// let start = Instant::now();
// let mut actor = LoroDoc::default();
// actor.import_batch(&updates).unwrap();
// println!("{} bytes", updates.iter().map(|x| x.len()).sum::<usize>());
// // dbg!(actor.get_state_deep_value());
// println!("{} ms", start.elapsed().as_millis());
// drop(profiler);
}
fn with_100K_actors_then_action() {
let store = LoroDoc::default();
for i in 0..100_000 {
store.set_peer_id(i);
let list = store.get_list("list");
let value: LoroValue = i.to_string().into();
let mut txn = store.txn().unwrap();
list.insert(&mut txn, 0, value).unwrap();
txn.commit().unwrap();
}
for i in 0..200_000 {
let list = store.get_list("list");
let value: LoroValue = i.to_string().into();
let mut txn = store.txn().unwrap();
list.insert(&mut txn, 0, value).unwrap();
txn.commit().unwrap();
}
}