Merge branch 'main' into feat-encode-enhance

This commit is contained in:
Zixuan Chen 2023-09-05 17:08:41 +08:00
commit be63db444e
No known key found for this signature in database
4 changed files with 71 additions and 1 deletions

View 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
}

View file

@ -1,3 +1,4 @@
pub mod draw;
use arbitrary::Arbitrary; use arbitrary::Arbitrary;
use enum_as_inner::EnumAsInner; use enum_as_inner::EnumAsInner;
use rand::{rngs::StdRng, RngCore, SeedableRng}; use rand::{rngs::StdRng, RngCore, SeedableRng};

View 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);

View file

@ -24,7 +24,7 @@ fn main() {
let data = loro.export_from(&Default::default()); let data = loro.export_from(&Default::default());
let start = Instant::now(); let start = Instant::now();
for _ in 0..10 { for _ in 0..100 {
let mut b = LoroDoc::default(); let mut b = LoroDoc::default();
b.detach(); b.detach();
b.import(&data).unwrap(); b.import(&data).unwrap();