Switch to Criterion for benchtests.

ci: Add benches to workflow.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2025-09-24 04:18:13 +00:00
parent a47f8f8a82
commit 89be6dc097
17 changed files with 334 additions and 166 deletions

View File

@@ -11,11 +11,16 @@ version.workspace = true
[lib]
path = "mod.rs"
bench = false
crate-type = [
"rlib",
# "dylib",
]
[[bench]]
name = "ser"
harness = false
[features]
bzip2_compression = [
"rust-rocksdb/bzip2",
@@ -66,5 +71,8 @@ tokio.workspace = true
tracing.workspace = true
tuwunel-core.workspace = true
[dev-dependencies]
criterion.workspace = true
[lints]
workspace = true

View File

@@ -1,17 +0,0 @@
#[cfg(tuwunel_bench)]
extern crate test;
#[cfg(tuwunel_bench)]
#[cfg_attr(tuwunel_bench, bench)]
fn ser_str(b: &mut test::Bencher) {
use tuwunel_core::ruma::{RoomId, UserId};
use crate::ser::serialize_to_vec;
let user_id: &UserId = "@user:example.com".try_into().unwrap();
let room_id: &RoomId = "!room:example.com".try_into().unwrap();
b.iter(|| {
let key = (user_id, room_id);
let _s = serialize_to_vec(key).expect("failed to serialize user_id");
});
}

View File

@@ -0,0 +1,19 @@
use criterion::{Criterion, criterion_group, criterion_main};
criterion_group!(benches, ser_str,);
criterion_main!(benches);
fn ser_str(b: &mut Criterion) {
b.bench_function("ser_str", |c| {
use tuwunel_core::ruma::{RoomId, UserId};
use tuwunel_database::serialize_to_vec;
let user_id: &UserId = "@user:example.com".try_into().unwrap();
let room_id: &RoomId = "!room:example.com".try_into().unwrap();
c.iter(|| {
let key = (user_id, room_id);
let _s = serialize_to_vec(key).expect("failed to serialize user_id");
});
});
}

View File

@@ -6,8 +6,6 @@ tuwunel_core::mod_ctor! {}
tuwunel_core::mod_dtor! {}
tuwunel_core::rustc_flags_capture! {}
#[cfg(test)]
mod benches;
mod cork;
mod de;
mod deserialized;