Files
AFFiNE-Mirror/packages/common/y-octo/utils/benches/codec_benchmarks.rs
DarkSky ca2462f987 feat(native): sync yocto codes (#14243)
#### PR Dependency Tree


* **PR #14243** 👈

This tree was auto-generated by
[Charcoal](https://github.com/danerwilliams/charcoal)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Batch management API for coordinated document mutations and change
tracking.
* New document accessors (IDs, state snapshots, change/delete set
queries) and subscriber count.

* **Chores**
  * Upgraded Rust edition across packages to 2024.
  * Repository-wide formatting, stylistic cleanups and test adjustments.

* **Breaking Changes**
* Removed the Node native bindings package and its JS/TS declarations
and tests (no longer published/available).

<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-01-11 06:08:33 +08:00

90 lines
2.5 KiB
Rust

use criterion::{Criterion, SamplingMode, criterion_group, criterion_main};
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);