Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ruma-events: Feature gate criterion to avoid compilation in CI #111

Merged
merged 4 commits into from Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion ruma-events/Cargo.toml
Expand Up @@ -27,7 +27,13 @@ maplit = "1.0.2"
matches = "0.1.8"
ruma-identifiers = { version = "0.16.2", path = "../ruma-identifiers", features = ["rand"] }
trybuild = "1.0.30"
criterion = "0.3.2"

[dependencies.criterion]
DevinR528 marked this conversation as resolved.
Show resolved Hide resolved
version = "0.3.2"
optional = true

[features]
default = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm relatively certain this is unnecessary.


[[bench]]
name = "event_deserialize"
Expand Down
18 changes: 17 additions & 1 deletion ruma-events/benches/event_deserialize.rs
Expand Up @@ -2,8 +2,11 @@
// or pass any other args to it, it fails with the error
// `cargo bench unknown option --save-baseline`.
// To pass args to criterion, use this form
// `cargo bench --bench <name of the bench> -- --save-baseline <name>`.
// `cargo bench --features criterion --bench <name of the bench> -- --save-baseline <name>`.

#![allow(unused_imports, dead_code)]

#[cfg(feature = "criterion")]
use criterion::{criterion_group, criterion_main, Criterion};
use ruma_events::{
room::power_levels::PowerLevelsEventContent, AnyEvent, AnyRoomEvent, AnyStateEvent, EventJson,
Expand Down Expand Up @@ -44,6 +47,7 @@ fn power_levels() -> serde_json::Value {
})
}

#[cfg(feature = "criterion")]
fn deserialize_any_event(c: &mut Criterion) {
let json_data = power_levels();

Expand All @@ -57,6 +61,7 @@ fn deserialize_any_event(c: &mut Criterion) {
});
}

#[cfg(feature = "criterion")]
fn deserialize_any_room_event(c: &mut Criterion) {
let json_data = power_levels();

Expand All @@ -70,6 +75,7 @@ fn deserialize_any_room_event(c: &mut Criterion) {
});
}

#[cfg(feature = "criterion")]
fn deserialize_any_state_event(c: &mut Criterion) {
let json_data = power_levels();

Expand All @@ -83,6 +89,7 @@ fn deserialize_any_state_event(c: &mut Criterion) {
});
}

#[cfg(feature = "criterion")]
fn deserialize_specific_event(c: &mut Criterion) {
let json_data = power_levels();

Expand All @@ -98,6 +105,7 @@ fn deserialize_specific_event(c: &mut Criterion) {
});
}

#[cfg(feature = "criterion")]
criterion_group!(
benches,
deserialize_any_event,
Expand All @@ -106,4 +114,12 @@ criterion_group!(
deserialize_specific_event
);

#[cfg(feature = "criterion")]
criterion_main!(benches);

#[cfg(not(feature = "criterion"))]
fn main() {
// To run the benchmarks the "criterion" feature must be enabled use:
// `cargo bench --features criterion --bench event_deserialize`
panic!("Enable the criterion feature to run benchmarks");
}