-
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move compatibility test to utils (y-crdt/y-octo#27)
- Loading branch information
1 parent
d34fe0f
commit 90ba069
Showing
54 changed files
with
912 additions
and
1,592 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
use std::time::Duration; | ||
|
||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use rand::{Rng, SeedableRng}; | ||
|
||
fn operations(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("ops/array"); | ||
group.measurement_time(Duration::from_secs(15)); | ||
|
||
group.bench_function("yrs/insert", |b| { | ||
let base_text = "test1 test2 test3 test4 test5 test6 test7 test8 test9"; | ||
let mut rng = rand_chacha::ChaCha20Rng::seed_from_u64(1234); | ||
|
||
let idxs = (0..99) | ||
.map(|_| rng.gen_range(0..base_text.len() as u32)) | ||
.collect::<Vec<_>>(); | ||
b.iter(|| { | ||
use yrs::*; | ||
let doc = Doc::new(); | ||
let array = doc.get_or_insert_array("test"); | ||
|
||
let mut trx = doc.transact_mut(); | ||
for c in base_text.chars() { | ||
array.push_back(&mut trx, c.to_string()).unwrap(); | ||
} | ||
for idx in &idxs { | ||
array.insert(&mut trx, *idx, "test").unwrap(); | ||
} | ||
drop(trx); | ||
}); | ||
}); | ||
|
||
group.bench_function("yrs/insert range", |b| { | ||
let base_text = "test1 test2 test3 test4 test5 test6 test7 test8 test9"; | ||
let mut rng = rand_chacha::ChaCha20Rng::seed_from_u64(1234); | ||
|
||
let idxs = (0..99) | ||
.map(|_| rng.gen_range(0..base_text.len() as u32)) | ||
.collect::<Vec<_>>(); | ||
b.iter(|| { | ||
use yrs::*; | ||
let doc = Doc::new(); | ||
let array = doc.get_or_insert_array("test"); | ||
|
||
let mut trx = doc.transact_mut(); | ||
for c in base_text.chars() { | ||
array.push_back(&mut trx, c.to_string()).unwrap(); | ||
} | ||
for idx in &idxs { | ||
array.insert_range(&mut trx, *idx, vec!["test1", "test2"]).unwrap(); | ||
} | ||
drop(trx); | ||
}); | ||
}); | ||
|
||
group.bench_function("yrs/remove", |b| { | ||
let base_text = "test1 test2 test3 test4 test5 test6 test7 test8 test9"; | ||
|
||
b.iter(|| { | ||
use yrs::*; | ||
let doc = Doc::new(); | ||
let array = doc.get_or_insert_array("test"); | ||
|
||
let mut trx = doc.transact_mut(); | ||
for c in base_text.chars() { | ||
array.push_back(&mut trx, c.to_string()).unwrap(); | ||
} | ||
for idx in (base_text.len() as u32)..0 { | ||
array.remove(&mut trx, idx).unwrap(); | ||
} | ||
drop(trx); | ||
}); | ||
}); | ||
|
||
group.finish(); | ||
} | ||
|
||
criterion_group!(benches, operations); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
use criterion::{criterion_group, criterion_main, Criterion, SamplingMode}; | ||
use lib0::{ | ||
decoding::{Cursor, Read}, | ||
encoding::Write, | ||
}; | ||
|
||
const BENCHMARK_SIZE: u32 = 100000; | ||
|
||
fn codec(c: &mut Criterion) { | ||
let mut codec_group = c.benchmark_group("codec"); | ||
codec_group.sampling_mode(SamplingMode::Flat); | ||
{ | ||
codec_group.bench_function("lib0 encode var_int (64 bit)", |b| { | ||
b.iter(|| { | ||
let mut encoder = Vec::with_capacity(BENCHMARK_SIZE as usize * 8); | ||
for i in 0..(BENCHMARK_SIZE as i64) { | ||
encoder.write_var(i); | ||
} | ||
}) | ||
}); | ||
codec_group.bench_function("lib0 decode var_int (64 bit)", |b| { | ||
let mut encoder = Vec::with_capacity(BENCHMARK_SIZE as usize * 8); | ||
for i in 0..(BENCHMARK_SIZE as i64) { | ||
encoder.write_var(i); | ||
} | ||
|
||
b.iter(|| { | ||
let mut decoder = Cursor::from(&encoder); | ||
for i in 0..(BENCHMARK_SIZE as i64) { | ||
let num: i64 = decoder.read_var().unwrap(); | ||
assert_eq!(num, i); | ||
} | ||
}) | ||
}); | ||
} | ||
|
||
{ | ||
codec_group.bench_function("lib0 encode var_uint (32 bit)", |b| { | ||
b.iter(|| { | ||
let mut encoder = Vec::with_capacity(BENCHMARK_SIZE as usize * 8); | ||
for i in 0..BENCHMARK_SIZE { | ||
encoder.write_var(i); | ||
} | ||
}) | ||
}); | ||
codec_group.bench_function("lib0 decode var_uint (32 bit)", |b| { | ||
let mut encoder = Vec::with_capacity(BENCHMARK_SIZE as usize * 8); | ||
for i in 0..BENCHMARK_SIZE { | ||
encoder.write_var(i); | ||
} | ||
|
||
b.iter(|| { | ||
let mut decoder = Cursor::from(&encoder); | ||
for i in 0..BENCHMARK_SIZE { | ||
let num: u32 = decoder.read_var().unwrap(); | ||
assert_eq!(num, i); | ||
} | ||
}) | ||
}); | ||
} | ||
|
||
{ | ||
codec_group.bench_function("lib0 encode var_uint (64 bit)", |b| { | ||
b.iter(|| { | ||
let mut encoder = Vec::with_capacity(BENCHMARK_SIZE as usize * 8); | ||
for i in 0..(BENCHMARK_SIZE as u64) { | ||
encoder.write_var(i); | ||
} | ||
}) | ||
}); | ||
codec_group.bench_function("lib0 decode var_uint (64 bit)", |b| { | ||
let mut encoder = Vec::with_capacity(BENCHMARK_SIZE as usize * 8); | ||
for i in 0..(BENCHMARK_SIZE as u64) { | ||
encoder.write_var(i); | ||
} | ||
|
||
b.iter(|| { | ||
let mut decoder = Cursor::from(&encoder); | ||
for i in 0..(BENCHMARK_SIZE as u64) { | ||
let num: u64 = decoder.read_var().unwrap(); | ||
assert_eq!(num, i); | ||
} | ||
}) | ||
}); | ||
} | ||
} | ||
|
||
criterion_group!(benches, codec); | ||
criterion_main!(benches); |
Oops, something went wrong.