mirror of
https://github.com/loro-dev/loro.git
synced 2025-01-22 12:57:20 +00:00
test: add B4 bench
This commit is contained in:
parent
fa2db1be7e
commit
22465a5e97
4 changed files with 61 additions and 1 deletions
21
Cargo.lock
generated
21
Cargo.lock
generated
|
@ -236,6 +236,15 @@ dependencies = [
|
|||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crc32fast"
|
||||
version = "1.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crdt-list"
|
||||
version = "0.3.0"
|
||||
|
@ -409,6 +418,16 @@ dependencies = [
|
|||
"instant",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f82b0f4c27ad9f8bfd1f3208d882da2b09c301bc1c828fd3a00d0216d2fbbff6"
|
||||
dependencies = [
|
||||
"crc32fast",
|
||||
"miniz_oxide",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fnv"
|
||||
version = "1.0.7"
|
||||
|
@ -579,6 +598,7 @@ dependencies = [
|
|||
"ctor",
|
||||
"dhat",
|
||||
"enum-as-inner",
|
||||
"flate2",
|
||||
"fxhash",
|
||||
"im",
|
||||
"js-sys",
|
||||
|
@ -591,6 +611,7 @@ dependencies = [
|
|||
"ring",
|
||||
"rle",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"smallvec",
|
||||
"smartstring",
|
||||
"static_assertions",
|
||||
|
|
|
@ -38,6 +38,8 @@ tabled = "0.10.0"
|
|||
color-backtrace = { version = "0.5" }
|
||||
ctor = "0.1.23"
|
||||
criterion = "0.4.0"
|
||||
serde_json = "1.0.87"
|
||||
flate2 = "1.0.24"
|
||||
|
||||
# See https://matklad.github.io/2021/02/27/delete-cargo-integration-tests.html
|
||||
[lib]
|
||||
|
|
BIN
crates/loro-core/benches/automerge-paper.json.gz
Normal file
BIN
crates/loro-core/benches/automerge-paper.json.gz
Normal file
Binary file not shown.
|
@ -1,12 +1,19 @@
|
|||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
const RAW_DATA: &[u8; 901823] = include_bytes!("automerge-paper.json.gz");
|
||||
|
||||
#[cfg(feature = "fuzzing")]
|
||||
mod run {
|
||||
use std::io::Read;
|
||||
|
||||
use super::*;
|
||||
use arbitrary::Unstructured;
|
||||
use flate2::read::GzDecoder;
|
||||
use loro_core::fuzz::test_multi_sites;
|
||||
use loro_core::fuzz::Action;
|
||||
use loro_core::LoroCore;
|
||||
use rand::Rng;
|
||||
use rand::SeedableRng;
|
||||
use serde_json::Value;
|
||||
|
||||
pub fn criterion_benchmark(c: &mut Criterion) {
|
||||
let mut rgn = rand::rngs::StdRng::seed_from_u64(0);
|
||||
|
@ -21,11 +28,41 @@ mod run {
|
|||
b.iter(|| test_multi_sites(2, actions.clone().into()))
|
||||
});
|
||||
}
|
||||
|
||||
pub fn b4(c: &mut Criterion) {
|
||||
let mut d = GzDecoder::new(&RAW_DATA[..]);
|
||||
let mut s = String::new();
|
||||
d.read_to_string(&mut s).unwrap();
|
||||
let json: Value = serde_json::from_str(&s).unwrap();
|
||||
let txns = json.as_object().unwrap().get("txns");
|
||||
c.bench_function("B4", |b| {
|
||||
b.iter(|| {
|
||||
let mut loro = LoroCore::default();
|
||||
let mut text = loro.get_or_create_root_text("text").unwrap();
|
||||
for txn in txns.unwrap().as_array().unwrap() {
|
||||
let patches = txn
|
||||
.as_object()
|
||||
.unwrap()
|
||||
.get("patches")
|
||||
.unwrap()
|
||||
.as_array()
|
||||
.unwrap();
|
||||
for patch in patches {
|
||||
let pos = patch[0].as_u64().unwrap() as usize;
|
||||
let del_here = patch[1].as_u64().unwrap() as usize;
|
||||
let ins_content = patch[2].as_str().unwrap();
|
||||
text.delete(pos, del_here);
|
||||
text.insert(pos, ins_content);
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
pub fn dumb(_c: &mut Criterion) {}
|
||||
|
||||
#[cfg(feature = "fuzzing")]
|
||||
criterion_group!(benches, run::criterion_benchmark);
|
||||
criterion_group!(benches, run::criterion_benchmark, run::b4);
|
||||
#[cfg(not(feature = "fuzzing"))]
|
||||
criterion_group!(benches, dumb);
|
||||
criterion_main!(benches);
|
||||
|
|
Loading…
Reference in a new issue