2023-10-29 06:02:13 +00:00
|
|
|
use std::time::Instant;
|
2022-12-12 17:39:57 +00:00
|
|
|
|
2023-07-31 03:49:55 +00:00
|
|
|
use loro_internal::{LoroDoc, LoroValue};
|
2023-09-02 15:23:52 +00:00
|
|
|
// #[global_allocator]
|
|
|
|
// static ALLOC: dhat::Alloc = dhat::Alloc;
|
2022-12-08 15:02:44 +00:00
|
|
|
|
|
|
|
fn main() {
|
2023-10-29 06:02:13 +00:00
|
|
|
with_100k_actors_then_action();
|
2023-09-02 15:23:52 +00:00
|
|
|
// import_with_many_actors();
|
|
|
|
}
|
|
|
|
|
2023-10-29 06:02:13 +00:00
|
|
|
#[allow(unused)]
|
2023-09-02 15:23:52 +00:00
|
|
|
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");
|
2022-12-08 15:02:44 +00:00
|
|
|
let value: LoroValue = i.to_string().into();
|
2023-09-02 15:23:52 +00:00
|
|
|
let mut txn = store.txn().unwrap();
|
2023-07-31 03:49:55 +00:00
|
|
|
list.insert(&mut txn, 0, value).unwrap();
|
2023-09-02 10:19:34 +00:00
|
|
|
txn.commit().unwrap();
|
2022-12-08 15:02:44 +00:00
|
|
|
}
|
|
|
|
|
2023-09-02 15:23:52 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2023-10-29 06:02:13 +00:00
|
|
|
#[allow(unused)]
|
|
|
|
fn with_100k_actors_then_action() {
|
2023-09-02 15:23:52 +00:00
|
|
|
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();
|
|
|
|
}
|
2023-07-31 03:49:55 +00:00
|
|
|
|
2023-09-02 15:23:52 +00:00
|
|
|
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();
|
|
|
|
}
|
2022-12-08 15:02:44 +00:00
|
|
|
}
|