Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Benchmark against simd math functions from core::intrinsics::simd #3

Merged
merged 3 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions benches/math.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#![feature(portable_simd, test, array_chunks, core_intrinsics)]
#![allow(internal_features)]
extern crate test;

#[path = "../tests/common/mod.rs"]
mod common;
use common::Linspace;

use simd_addons::math::Trigonometry;
use std::simd::prelude::*;

const BENCH_POINTS: usize = 200_000;

macro_rules! bench_simd_vs_scalar {
($range: expr, $func: tt, $ftype: ty $(, $coresimdfn: tt )?) => {
paste::paste! {
#[bench]
fn [< bench_ $func _ $ftype _vec >](b: &mut test::Bencher) {
#[allow(clippy::all)]
let data: Vec<_> = ($range as $ftype).linspace(BENCH_POINTS).collect();
b.iter(|| {
for x in test::black_box(data.array_chunks::<64>()) {
test::black_box(Simd::from_array(*x).$func());
}
})
}

#[bench]
fn [< bench_ $func _ $ftype _scalar >](b: &mut test::Bencher) {
#[allow(clippy::all)]
let data: Vec<_> = ($range as $ftype).linspace(BENCH_POINTS).collect();
b.iter(|| {
for x in test::black_box(&data) {
test::black_box(x.$func());
}
});
}

$(
#[bench]
fn [< bench_ $func _ $ftype _core_simd >](b: &mut test::Bencher) {
#[allow(clippy::all)]
let data: Vec<_> = ($range as $ftype).linspace(BENCH_POINTS).collect();
b.iter(|| {
for x in test::black_box(data.array_chunks::<64>()) {
test::black_box(unsafe { core::intrinsics::simd::$coresimdfn(Simd::from_array(*x)) });
}
})
}
)?
}
};
}

bench_simd_vs_scalar!(-1e4..1e4, sin, f32, simd_fsin);
bench_simd_vs_scalar!(-1e4..1e4, sin, f64, simd_fsin);
bench_simd_vs_scalar!(-1e4..1e4, cos, f32, simd_fcos);
bench_simd_vs_scalar!(-1e4..1e4, cos, f64, simd_fcos);
61 changes: 0 additions & 61 deletions benches/trig.rs

This file was deleted.

Loading