aboutsummaryrefslogtreecommitdiff
path: root/benches
diff options
context:
space:
mode:
authorJack O'Connor <[email protected]>2019-12-06 17:18:39 -0500
committerJack O'Connor <[email protected]>2019-12-06 17:18:39 -0500
commit4b2d85675463a42a2e9536cb97591206e7bd266c (patch)
tree024ea45a7991067fc40866926ce4b9c59314640f /benches
parent19471453f5df895122faf40f2142f12ace8ffd98 (diff)
add many_parents benchmarks
Diffstat (limited to 'benches')
-rw-r--r--benches/bench.rs80
1 files changed, 63 insertions, 17 deletions
diff --git a/benches/bench.rs b/benches/bench.rs
index 6303caf..490e415 100644
--- a/benches/bench.rs
+++ b/benches/bench.rs
@@ -4,6 +4,7 @@ extern crate test;
use arrayref::array_ref;
use arrayvec::ArrayVec;
+use blake3::platform::MAX_SIMD_DEGREE;
use blake3::{BLOCK_LEN, CHUNK_LEN, KEY_LEN, OUT_LEN};
use rand::prelude::*;
use test::Bencher;
@@ -55,7 +56,7 @@ type CompressFn = unsafe fn(
flags: u8,
) -> [u8; 64];
-fn bench_compress_fn(b: &mut Bencher, f: CompressFn) {
+fn bench_single_compression_fn(b: &mut Bencher, f: CompressFn) {
let state: [u8; 32];
let mut r = RandomInput::new(b, 64);
state = *array_ref!(r.get(), 0, 32);
@@ -66,17 +67,17 @@ fn bench_compress_fn(b: &mut Bencher, f: CompressFn) {
}
#[bench]
-fn bench_compress_portable(b: &mut Bencher) {
- bench_compress_fn(b, blake3::portable::compress);
+fn bench_single_compression_portable(b: &mut Bencher) {
+ bench_single_compression_fn(b, blake3::portable::compress);
}
#[bench]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
-fn bench_compress_sse41(b: &mut Bencher) {
+fn bench_single_compression_sse41(b: &mut Bencher) {
if !blake3::platform::sse41_detected() {
return;
}
- bench_compress_fn(b, blake3::sse41::compress);
+ bench_single_compression_fn(b, blake3::sse41::compress);
}
type HashManyFn<A> = unsafe fn(
@@ -90,20 +91,19 @@ type HashManyFn<A> = unsafe fn(
out: &mut [u8],
);
-fn bench_hash_many_fn(b: &mut Bencher, f: HashManyFn<[u8; CHUNK_LEN]>, degree: usize) {
+fn bench_many_chunks_fn(b: &mut Bencher, f: HashManyFn<[u8; CHUNK_LEN]>, degree: usize) {
let mut inputs = Vec::new();
for _ in 0..degree {
inputs.push(RandomInput::new(b, CHUNK_LEN));
}
unsafe {
b.iter(|| {
- let input_arrays: ArrayVec<[&[u8; CHUNK_LEN]; blake3::platform::MAX_SIMD_DEGREE]> =
- inputs
- .iter_mut()
- .take(degree)
- .map(|i| array_ref!(i.get(), 0, CHUNK_LEN))
- .collect();
- let mut out = [0; blake3::platform::MAX_SIMD_DEGREE * OUT_LEN];
+ let input_arrays: ArrayVec<[&[u8; CHUNK_LEN]; MAX_SIMD_DEGREE]> = inputs
+ .iter_mut()
+ .take(degree)
+ .map(|i| array_ref!(i.get(), 0, CHUNK_LEN))
+ .collect();
+ let mut out = [0; MAX_SIMD_DEGREE * OUT_LEN];
f(
&input_arrays[..],
&[0; KEY_LEN],
@@ -120,20 +120,66 @@ fn bench_hash_many_fn(b: &mut Bencher, f: HashManyFn<[u8; CHUNK_LEN]>, degree: u
#[bench]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
-fn bench_many_sse41(b: &mut Bencher) {
+fn bench_many_chunks_sse41(b: &mut Bencher) {
if !blake3::platform::sse41_detected() {
return;
}
- bench_hash_many_fn(b, blake3::sse41::hash_many, blake3::sse41::DEGREE);
+ bench_many_chunks_fn(b, blake3::sse41::hash_many, blake3::sse41::DEGREE);
}
#[bench]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
-fn bench_many_avx2(b: &mut Bencher) {
+fn bench_many_chunks_avx2(b: &mut Bencher) {
if !blake3::platform::avx2_detected() {
return;
}
- bench_hash_many_fn(b, blake3::avx2::hash_many, blake3::avx2::DEGREE);
+ bench_many_chunks_fn(b, blake3::avx2::hash_many, blake3::avx2::DEGREE);
+}
+
+// TODO: When we get const generics we can unify this with the chunks code.
+fn bench_many_parents_fn(b: &mut Bencher, f: HashManyFn<[u8; BLOCK_LEN]>, degree: usize) {
+ let mut inputs = Vec::new();
+ for _ in 0..degree {
+ inputs.push(RandomInput::new(b, BLOCK_LEN));
+ }
+ unsafe {
+ b.iter(|| {
+ let input_arrays: ArrayVec<[&[u8; BLOCK_LEN]; MAX_SIMD_DEGREE]> = inputs
+ .iter_mut()
+ .take(degree)
+ .map(|i| array_ref!(i.get(), 0, BLOCK_LEN))
+ .collect();
+ let mut out = [0; MAX_SIMD_DEGREE * OUT_LEN];
+ f(
+ &input_arrays[..],
+ &[0; KEY_LEN],
+ 0,
+ &[0; 16],
+ 0,
+ 0,
+ 0,
+ &mut out,
+ );
+ });
+ }
+}
+
+#[bench]
+#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
+fn bench_many_parents_sse41(b: &mut Bencher) {
+ if !blake3::platform::sse41_detected() {
+ return;
+ }
+ bench_many_parents_fn(b, blake3::sse41::hash_many, blake3::sse41::DEGREE);
+}
+
+#[bench]
+#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
+fn bench_many_parents_avx2(b: &mut Bencher) {
+ if !blake3::platform::avx2_detected() {
+ return;
+ }
+ bench_many_parents_fn(b, blake3::avx2::hash_many, blake3::avx2::DEGREE);
}
fn bench_atonce(b: &mut Bencher, len: usize) {