forge
Explore
Log in

Don't you dare go Hollow

project_note

Clone
★ 0

0 watching0 forksRust3.6 MiBc49f5e7Tahinli1 month ago2 commits

mem.rs110 lines, 3.9 KiBHistoryRawDownload
1// #[global_allocator]
2// static ALLOC: dhat::Alloc = dhat::Alloc;
3
4// use std::time::Instant;
5
6// use bench_utils::TextAction;
7// use loro_internal::LoroDoc;
8
9// fn apply_automerge(times: usize) {
10// let actions = bench_utils::get_automerge_actions();
11// let start = Instant::now();
12// let profiler = dhat::Profiler::builder().trim_backtraces(None).build();
13// let mut loro = LoroCore::default();
14// let mut text = loro.get_text("text");
15// println!("Apply Automerge Dataset 1X");
16// for _i in 0..times {
17// for TextAction { pos, ins, del } in actions.iter() {
18// text.delete(&loro, *pos, *del).unwrap();
19// text.insert(&loro, *pos, ins).unwrap();
20// }
21// }
22// drop(profiler);
23// println!("Used: {} ms", start.elapsed().as_millis());
24// }
25
26// fn concurrent_actors(actor_num: usize) {
27// let mut actors: Vec<LoroCore> = Vec::new();
28// for _ in 0..actor_num {
29// actors.push(LoroCore::default());
30// }
31
32// let mut updates = Vec::new();
33// for actor in actors.iter_mut() {
34// let mut list = actor.get_list("list");
35// list.insert(actor, 0, 1).unwrap();
36// updates.push(actor.encode_all());
37// }
38
39// let mut a = actors.drain(0..1).next().unwrap();
40// drop(actors);
41// let profiler = dhat::Profiler::builder().trim_backtraces(None).build();
42// for update in updates {
43// a.decode(&update).unwrap();
44// }
45// drop(profiler);
46// }
47
48// fn realtime_sync(actor_num: usize, action_num: usize) {
49// let actions = bench_utils::gen_realtime_actions(action_num, actor_num, 100);
50// let profiler = dhat::Profiler::builder().trim_backtraces(None).build();
51// let mut actors = Vec::new();
52// for _ in 0..actor_num {
53// actors.push(LoroDoc::default());
54// }
55
56// for action in actions {
57// match action {
58// bench_utils::Action::Text { client, action } => {
59// let mut text = actors[client].get_text("text");
60// let bench_utils::TextAction { pos, ins, del } = action;
61// let pos = pos % (text.len() + 1);
62// let del = del.min(text.len() - pos);
63// text.delete(&actors[client], pos, del).unwrap();
64// text.insert(&actors[client], pos, &ins).unwrap();
65// }
66// bench_utils::Action::SyncAll => {
67// let mut updates = Vec::new();
68// for i in 1..actor_num {
69// let (a, b) = arref::array_mut_ref!(&mut actors, [0, i]);
70// updates.push(b.encode_from(a.vv_cloned()));
71// }
72// for update in updates {
73// // TODO: use import batch here
74// actors[0].decode(&update).unwrap();
75// }
76// for i in 1..actor_num {
77// let (a, b) = arref::array_mut_ref!(&mut actors, [0, i]);
78// b.decode(&a.encode_from(b.vv_cloned())).unwrap();
79// }
80// }
81// }
82// }
83// drop(profiler);
84// }
85
86pub fn main() {
87 // let args: Vec<_> = std::env::args().collect();
88 // if args.len() < 2 {
89 // apply_automerge(1);
90 // return;
91 // }
92
93 // match args[1].as_str() {
94 // "automerge" => {
95 // apply_automerge(1);
96 // }
97 // "100_concurrent" => {
98 // concurrent_actors(100);
99 // }
100 // "200_concurrent" => {
101 // concurrent_actors(200);
102 // }
103 // "10_actor_sync_1000_actions" => realtime_sync(10, 1000),
104 // "20_actor_sync_1000_actions" => realtime_sync(20, 1000),
105 // "10_actor_sync_2000_actions" => realtime_sync(10, 2000),
106 // _ => {
107 // panic!("Unknown command `{}`", args.join(" "));
108 // }
109 // }
110}