mirror of
https://github.com/loro-dev/loro.git
synced 2024-12-01 04:28:18 +00:00
Merge branch 'main' into feat-encode-enhance
This commit is contained in:
commit
be63db444e
4 changed files with 71 additions and 1 deletions
33
crates/bench-utils/src/draw.rs
Normal file
33
crates/bench-utils/src/draw.rs
Normal file
|
@ -0,0 +1,33 @@
|
|||
use arbitrary::{Arbitrary, Unstructured};
|
||||
|
||||
#[derive(Arbitrary)]
|
||||
pub struct Point {
|
||||
pub x: i32,
|
||||
pub y: i32,
|
||||
}
|
||||
|
||||
#[derive(Arbitrary)]
|
||||
pub enum DrawAction {
|
||||
DrawPath {
|
||||
points: Vec<Point>,
|
||||
color: i32,
|
||||
},
|
||||
Text {
|
||||
id: i32,
|
||||
text: String,
|
||||
pos: Point,
|
||||
width: i32,
|
||||
height: i32,
|
||||
},
|
||||
}
|
||||
|
||||
pub fn gen_draw_actions(seed: u64, num: usize) -> Vec<DrawAction> {
|
||||
let be_bytes = seed.to_be_bytes();
|
||||
let mut gen = Unstructured::new(&be_bytes);
|
||||
let mut ans = vec![];
|
||||
for _ in 0..num {
|
||||
ans.push(gen.arbitrary().unwrap());
|
||||
}
|
||||
|
||||
ans
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
pub mod draw;
|
||||
use arbitrary::Arbitrary;
|
||||
use enum_as_inner::EnumAsInner;
|
||||
use rand::{rngs::StdRng, RngCore, SeedableRng};
|
||||
|
|
36
crates/loro-internal/benches/draw.rs
Normal file
36
crates/loro-internal/benches/draw.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
use bench_utils::draw::{gen_draw_actions, DrawAction};
|
||||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
use loro_internal::LoroDoc;
|
||||
|
||||
pub fn draw(c: &mut Criterion) {
|
||||
let mut data = None;
|
||||
c.bench_function("simulate drawing", |b| {
|
||||
if data.is_none() {
|
||||
data = Some(gen_draw_actions(100, 1000));
|
||||
}
|
||||
|
||||
let mut loro = LoroDoc::new();
|
||||
b.iter(|| {
|
||||
loro = LoroDoc::new();
|
||||
let paths = loro.get_list("all_paths");
|
||||
let texts = loro.get_list("all_texts");
|
||||
for action in data.as_ref().unwrap().iter() {
|
||||
match action {
|
||||
DrawAction::DrawPath { points, color } => {}
|
||||
DrawAction::Text {
|
||||
id,
|
||||
text,
|
||||
pos,
|
||||
width,
|
||||
height,
|
||||
} => todo!(),
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
println!("Snapshot size = {}", loro.export_snapshot().len())
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(benches, draw);
|
||||
criterion_main!(benches);
|
|
@ -24,7 +24,7 @@ fn main() {
|
|||
|
||||
let data = loro.export_from(&Default::default());
|
||||
let start = Instant::now();
|
||||
for _ in 0..10 {
|
||||
for _ in 0..100 {
|
||||
let mut b = LoroDoc::default();
|
||||
b.detach();
|
||||
b.import(&data).unwrap();
|
||||
|
|
Loading…
Reference in a new issue