-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from smu160/master
Restructure criterion benchmarks into groups
- Loading branch information
Showing
10 changed files
with
422 additions
and
404 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,53 @@ | ||
#![feature(portable_simd)] | ||
|
||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use simd_itertools::EqSimd; | ||
use simd_itertools::SIMD_LEN; | ||
use std::fmt::Debug; | ||
use std::simd::prelude::SimdPartialEq; | ||
use std::simd::Mask; | ||
use std::simd::{Simd, SimdElement}; | ||
use std::time::Duration; | ||
|
||
fn benchmark_contains<'a, T: 'static + Copy + PartialEq + Default + Debug>( | ||
_c: &mut Criterion, | ||
name: &str, | ||
len: usize, | ||
) where | ||
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; | ||
use simd_itertools::{EqSimd, SIMD_LEN}; | ||
use std::{ | ||
fmt::Debug, | ||
simd::{prelude::SimdPartialEq, Mask, Simd, SimdElement}, | ||
}; | ||
|
||
fn benchmark_eq<'a, T: 'static + Copy + PartialEq + Default + Debug>(c: &mut Criterion) | ||
where | ||
T: SimdElement + std::cmp::PartialEq, | ||
Simd<T, SIMD_LEN>: SimdPartialEq<Mask = Mask<T::Mask, SIMD_LEN>>, | ||
{ | ||
let v1 = black_box(vec![T::default(); len]); | ||
let v2 = black_box(vec![T::default(); len]); | ||
|
||
let mut group = Criterion::default() | ||
.warm_up_time(Duration::from_secs(1)) | ||
.measurement_time(Duration::from_secs(1)); | ||
|
||
group.bench_function(&format!("SIMD eq {} {}", name, len), |b| { | ||
b.iter(|| black_box(v1.iter().eq_simd(&v2.iter()))) | ||
}); | ||
group.bench_function(&format!("Scalar eq {} {}", name, len), |b| { | ||
b.iter(|| black_box(v1.iter().eq(&v2))) | ||
}); | ||
let mut group = c.benchmark_group(format!("eq-{}", std::any::type_name::<T>())); | ||
let mut len = 1; | ||
|
||
while len < (1 << 11) { | ||
let v1 = black_box(vec![T::default(); len]); | ||
let v2 = black_box(vec![T::default(); len]); | ||
|
||
group.throughput(Throughput::Elements(len as u64)); | ||
|
||
group.bench_function(BenchmarkId::new("SIMD", len), |b| { | ||
b.iter(|| black_box(v1.iter().eq_simd(&v2.iter()))) | ||
}); | ||
group.bench_function(BenchmarkId::new("Scalar", len), |b| { | ||
b.iter(|| black_box(v1.iter().eq(&v2))) | ||
}); | ||
|
||
len *= 10; | ||
} | ||
|
||
group.finish(); | ||
} | ||
|
||
fn criterion_benchmark(c: &mut Criterion) { | ||
for n in (0..200).map(|x| x * 10) { | ||
benchmark_contains::<u8>(c, "u8", n); | ||
benchmark_contains::<i8>(c, "i8", n); | ||
benchmark_contains::<u16>(c, "u16", n); | ||
benchmark_contains::<i16>(c, "i16", n); | ||
benchmark_contains::<u32>(c, "u32", n); | ||
benchmark_contains::<i32>(c, "i32", n); | ||
benchmark_contains::<u64>(c, "u64", n); | ||
benchmark_contains::<i64>(c, "i64", n); | ||
benchmark_contains::<isize>(c, "isize", n); | ||
benchmark_contains::<usize>(c, "usize", n); | ||
benchmark_contains::<f32>(c, "f32", n); | ||
benchmark_contains::<f64>(c, "f64", n); | ||
} | ||
benchmark_eq::<u8>(c); | ||
benchmark_eq::<i8>(c); | ||
benchmark_eq::<u16>(c); | ||
benchmark_eq::<i16>(c); | ||
benchmark_eq::<u32>(c); | ||
benchmark_eq::<i32>(c); | ||
benchmark_eq::<u64>(c); | ||
benchmark_eq::<i64>(c); | ||
benchmark_eq::<isize>(c); | ||
benchmark_eq::<usize>(c); | ||
benchmark_eq::<f32>(c); | ||
benchmark_eq::<f64>(c); | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); |
Oops, something went wrong.