valence/valence_protocol/benches/benches.rs

98 lines
2.5 KiB
Rust
Raw Normal View History

use std::time::Duration;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use valence_protocol::block::{PropName, PropValue};
use valence_protocol::{BlockKind, BlockState, ItemKind};
criterion_group! {
name = benches;
config = Criterion::default()
.measurement_time(Duration::from_secs(3));
targets = blocks
}
criterion_main!(benches);
fn blocks(c: &mut Criterion) {
let states = BlockKind::ALL.map(BlockKind::to_state);
c.bench_function("BlockState::from_kind", |b| {
b.iter(|| {
for kind in black_box(BlockKind::ALL) {
black_box(BlockState::from_kind(kind));
}
});
});
c.bench_function("BlockState::to_kind", |b| {
b.iter(|| {
for state in black_box(states) {
black_box(state.to_kind());
}
});
});
c.bench_function("BlockState::get", |b| {
b.iter(|| {
for state in black_box(states) {
black_box(state.get(PropName::Note));
}
});
});
c.bench_function("BlockState::set", |b| {
b.iter(|| {
for state in black_box(states) {
black_box(state.set(PropName::Note, PropValue::Didgeridoo));
}
});
});
c.bench_function("BlockState::is_liquid", |b| {
b.iter(|| {
for state in black_box(states) {
black_box(state.is_liquid());
}
});
});
c.bench_function("BlockState::is_opaque", |b| {
b.iter(|| {
for state in black_box(states) {
black_box(state.is_opaque());
}
})
});
c.bench_function("BlockState::is_replaceable", |b| {
b.iter(|| {
for state in black_box(states) {
black_box(state.is_replaceable());
}
})
});
c.bench_function("BlockState::luminance", |b| {
b.iter(|| {
for state in black_box(states) {
black_box(state.luminance());
}
})
});
c.bench_function("BlockKind::to_item_kind", |b| {
b.iter(|| {
for kind in black_box(BlockKind::ALL) {
black_box(kind.to_item_kind());
}
});
});
c.bench_function("BlockKind::from_item_kind", |b| {
b.iter(|| {
for kind in black_box(ItemKind::ALL) {
black_box(BlockKind::from_item_kind(kind));
}
});
});
}