-
-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
355 additions
and
325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,93 @@ | ||
use std::hint::black_box; | ||
|
||
use criterion::Criterion; | ||
use divan::Bencher; | ||
use valence::block::{BlockKind, BlockState, PropName, PropValue}; | ||
use valence::ItemKind; | ||
|
||
pub(crate) fn block(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("block"); | ||
|
||
let states = BlockKind::ALL.map(BlockKind::to_state); | ||
|
||
group.bench_function("BlockState::from_kind", |b| { | ||
b.iter(|| { | ||
for kind in black_box(BlockKind::ALL) { | ||
black_box(BlockState::from_kind(kind)); | ||
} | ||
}); | ||
#[divan::bench] | ||
pub fn from_kind(bencher: Bencher) { | ||
bencher.bench(|| { | ||
for kind in black_box(BlockKind::ALL) { | ||
black_box(BlockState::from_kind(kind)); | ||
} | ||
}); | ||
|
||
group.bench_function("BlockState::to_kind", |b| { | ||
b.iter(|| { | ||
for state in black_box(states) { | ||
black_box(state.to_kind()); | ||
} | ||
}); | ||
} | ||
#[divan::bench] | ||
pub fn to_kind(bencher: Bencher) { | ||
let states = BlockKind::ALL.map(BlockKind::to_state); | ||
bencher.bench(|| { | ||
for state in black_box(states) { | ||
black_box(state.to_kind()); | ||
} | ||
}); | ||
|
||
group.bench_function("BlockState::get", |b| { | ||
b.iter(|| { | ||
for state in black_box(states) { | ||
black_box(state.get(PropName::Note)); | ||
} | ||
}); | ||
} | ||
#[divan::bench] | ||
pub fn get_prop(bencher: Bencher) { | ||
let states = BlockKind::ALL.map(BlockKind::to_state); | ||
bencher.bench(|| { | ||
for state in black_box(states) { | ||
black_box(state.get(PropName::Note)); | ||
} | ||
}); | ||
|
||
group.bench_function("BlockState::set", |b| { | ||
b.iter(|| { | ||
for state in black_box(states) { | ||
black_box(state.set(PropName::Note, PropValue::Didgeridoo)); | ||
} | ||
}); | ||
} | ||
#[divan::bench] | ||
pub fn set_prop(bencher: Bencher) { | ||
let states = BlockKind::ALL.map(BlockKind::to_state); | ||
bencher.bench(|| { | ||
for state in black_box(states) { | ||
black_box(state.set(PropName::Note, PropValue::Didgeridoo)); | ||
} | ||
}); | ||
|
||
group.bench_function("BlockState::is_liquid", |b| { | ||
b.iter(|| { | ||
for state in black_box(states) { | ||
black_box(state.is_liquid()); | ||
} | ||
}); | ||
} | ||
#[divan::bench] | ||
pub fn is_liquid(bencher: Bencher) { | ||
let states = BlockKind::ALL.map(BlockKind::to_state); | ||
bencher.bench(|| { | ||
for state in black_box(states) { | ||
black_box(state.is_liquid()); | ||
} | ||
}); | ||
|
||
group.bench_function("BlockState::is_opaque", |b| { | ||
b.iter(|| { | ||
for state in black_box(states) { | ||
black_box(state.is_opaque()); | ||
} | ||
}) | ||
} | ||
#[divan::bench] | ||
pub fn is_opaque(bencher: Bencher) { | ||
let states = BlockKind::ALL.map(BlockKind::to_state); | ||
bencher.bench(|| { | ||
for state in black_box(states) { | ||
black_box(state.is_opaque()); | ||
} | ||
}); | ||
|
||
group.bench_function("BlockState::is_replaceable", |b| { | ||
b.iter(|| { | ||
for state in black_box(states) { | ||
black_box(state.is_replaceable()); | ||
} | ||
}) | ||
} | ||
#[divan::bench] | ||
pub fn is_replaceable(bencher: Bencher) { | ||
let states = BlockKind::ALL.map(BlockKind::to_state); | ||
bencher.bench(|| { | ||
for state in black_box(states) { | ||
black_box(state.is_replaceable()); | ||
} | ||
}); | ||
|
||
group.bench_function("BlockState::luminance", |b| { | ||
b.iter(|| { | ||
for state in black_box(states) { | ||
black_box(state.luminance()); | ||
} | ||
}) | ||
} | ||
#[divan::bench] | ||
pub fn luminance(bencher: Bencher) { | ||
let states = BlockKind::ALL.map(BlockKind::to_state); | ||
bencher.bench(|| { | ||
for state in black_box(states) { | ||
black_box(state.luminance()); | ||
} | ||
}); | ||
|
||
group.bench_function("BlockKind::to_item_kind", |b| { | ||
b.iter(|| { | ||
for kind in black_box(BlockKind::ALL) { | ||
black_box(kind.to_item_kind()); | ||
} | ||
}); | ||
} | ||
#[divan::bench] | ||
pub fn to_item_kind(bencher: Bencher) { | ||
bencher.bench(|| { | ||
for kind in black_box(BlockKind::ALL) { | ||
black_box(kind.to_item_kind()); | ||
} | ||
}); | ||
|
||
group.bench_function("BlockKind::from_item_kind", |b| { | ||
b.iter(|| { | ||
for kind in black_box(ItemKind::ALL) { | ||
black_box(BlockKind::from_item_kind(kind)); | ||
} | ||
}); | ||
} | ||
#[divan::bench] | ||
pub fn from_item_kind(bencher: Bencher) { | ||
bencher.bench(|| { | ||
for kind in black_box(ItemKind::ALL) { | ||
black_box(BlockKind::from_item_kind(kind)); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,27 @@ | ||
use std::hint::black_box; | ||
|
||
use criterion::Criterion; | ||
use divan::Bencher; | ||
use valence::protocol::{Decode, Encode}; | ||
|
||
pub(crate) fn decode_array(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("decode_array"); | ||
|
||
#[divan::bench] | ||
pub fn decode_small_array(bencher: Bencher) { | ||
let floats = [123.0, 456.0, 789.0]; | ||
let mut buf = [0_u8; 24]; | ||
|
||
floats.encode(buf.as_mut_slice()).unwrap(); | ||
|
||
group.bench_function("<[f64; 3]>::decode", |b| { | ||
b.iter(|| { | ||
let mut r = black_box(buf.as_slice()); | ||
let _ = black_box(<[f64; 3]>::decode(&mut r)); | ||
}); | ||
bencher.bench(|| { | ||
let mut r = black_box(buf.as_slice()); | ||
let _ = black_box(<[f64; 3]>::decode(&mut r)); | ||
}); | ||
} | ||
|
||
#[divan::bench] | ||
pub fn decode_large_array(bencher: Bencher) { | ||
let bytes = [42; 4096]; | ||
|
||
group.bench_function("<[u8; 4096]>::decode", |b| { | ||
b.iter(|| { | ||
let mut r = black_box(bytes.as_slice()); | ||
let _ = black_box(<[u8; 4096]>::decode(&mut r)); | ||
}) | ||
bencher.bench(|| { | ||
let mut r = black_box(bytes.as_slice()); | ||
let _ = black_box(<[u8; 4096]>::decode(&mut r)); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.