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