Created
July 1, 2018 18:50
-
-
Save jackmott/a0b8ca811d2cf2ecb97a35f0aee0a5c6 to your computer and use it in GitHub Desktop.
faster benchmark
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
#[macro_use] | |
extern crate criterion; | |
extern crate faster; | |
extern crate simdeez; | |
use criterion::Criterion; | |
use criterion::Fun; | |
use faster::*; | |
use simdeez::*; | |
use simdeez::sse2::*; | |
#[inline(always)] | |
unsafe fn simdeezfunc<S:Simd>() -> Vec<f32> { | |
let slice = &[-123.456f32; 128][..]; | |
let vector_width = S::WIDTH_BYTES/4; | |
let mut result : Vec<f32> = Vec::with_capacity(128); | |
result.set_len(128); | |
let mut i = 0; | |
while i < 128 { | |
let v = S::loadu_ps(&slice[i]); | |
let mut r = S::mul_ps(S::set1_ps(9.0),S::sqrt_ps(S::ceil_ps(S::rsqrt_ps(S::sqrt_ps(S::abs_ps(v)))))); | |
r = S::sub_ps(S::sub_ps(r,S::set1_ps(4.0)),S::set1_ps(2.0)); | |
S::storeu_ps(&mut result[i],r); | |
i += vector_width | |
} | |
result | |
} | |
#[target_feature(enable="sse2")] | |
unsafe fn simdeez_sse2() -> Vec<f32> { | |
simdeezfunc::<Sse2>() | |
} | |
fn b(c: &mut Criterion) { | |
let f = Fun::new("faster 3333", |b, _i| { | |
b.iter(|| { | |
(&[-123.456f32; 128][..]) | |
.simd_iter(f32s(0.0)) | |
.simd_map(|v| { | |
f32s(9.0) * v.abs().sqrt().rsqrt().ceil().sqrt() - f32s(4.0) - f32s(2.0) | |
}) | |
.scalar_collect() | |
}) | |
}); | |
let s = Fun::new("simdeez 3333", |b, _i| b.iter(|| | |
unsafe { simdeez_sse2() } | |
)); | |
let functions = vec![f, s]; | |
c.bench_functions("b", functions, 0); | |
} | |
criterion_group!(benches, b); | |
criterion_main!(benches); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment