Switch to Criterion for benchtests.
ci: Add benches to workflow. Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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");
|
||||
});
|
||||
}
|
||||
19
src/database/benches/ser.rs
Normal file
19
src/database/benches/ser.rs
Normal 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");
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user