From 33ee72fbfbb83a74da783e011b17060af3163379 Mon Sep 17 00:00:00 2001 From: Saveliy Yusufov Date: Wed, 17 Jul 2024 18:09:53 -0400 Subject: [PATCH 01/12] Restructure criterion benchmarks into groups --- Cargo.lock | 2 +- benches/all_equal.rs | 81 ++++++++++++----------- benches/contains.rs | 144 ++++++++++++++++++++--------------------- benches/eq.rs | 96 ++++++++++++++-------------- benches/filter.rs | 102 ++++++++++++++--------------- benches/find.rs | 148 ++++++++++++++++++++++--------------------- benches/is_sorted.rs | 100 +++++++++++++++-------------- benches/max.rs | 92 ++++++++++++++------------- benches/min.rs | 90 +++++++++++++------------- benches/position.rs | 148 ++++++++++++++++++++++--------------------- 10 files changed, 509 insertions(+), 494 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3cf5d1f..7771a4a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -461,7 +461,7 @@ dependencies = [ [[package]] name = "simd-itertools" -version = "0.1.0" +version = "0.2.3" dependencies = [ "criterion", "itertools 0.13.0", diff --git a/benches/all_equal.rs b/benches/all_equal.rs index 61435f6..eca9b95 100644 --- a/benches/all_equal.rs +++ b/benches/all_equal.rs @@ -1,54 +1,53 @@ #![feature(portable_simd)] #![feature(is_sorted)] -use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; use itertools::Itertools; -use simd_itertools::AllEqualSimd; -use simd_itertools::SIMD_LEN; -use std::fmt::Debug; -use std::simd::prelude::SimdPartialEq; -use std::simd::Mask; -use std::simd::Simd; -use std::simd::SimdElement; -use std::time::Duration; - -fn benchmark_all_equal<'a, T: 'static + Copy + PartialEq + Default + Debug>( - _c: &mut Criterion, - name: &str, - len: usize, -) where +use simd_itertools::{AllEqualSimd, SIMD_LEN}; +use std::{ + fmt::Debug, + simd::{prelude::SimdPartialEq, Mask, Simd, SimdElement}, +}; + +fn benchmark_all_equal<'a, T: 'static + Copy + PartialEq + Default + Debug>(c: &mut Criterion) +where T: SimdElement + std::cmp::PartialEq, Simd: SimdPartialEq>, { - let v1 = 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 all_equal {} {}", name, len), |b| { - b.iter(|| black_box(v1.iter().all_equal_simd())) - }); - group.bench_function(&format!("Scalar all_equal {} {}", name, len), |b| { - b.iter(|| black_box(v1.iter().all_equal())) - }); + let mut group = c.benchmark_group(format!("all-equal-{}", std::any::type_name::())); + let mut len = 1; + + while len < (1 << 11) { + let v1 = 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().all_equal_simd())) + }); + group.bench_function(BenchmarkId::new("Scalar", len), |b| { + b.iter(|| black_box(v1.iter().all_equal())) + }); + + len *= 10; + } + + group.finish(); } fn criterion_benchmark(c: &mut Criterion) { - for n in (0..200).map(|x| x * 10) { - benchmark_all_equal::(c, "u8", n); - benchmark_all_equal::(c, "i8", n); - benchmark_all_equal::(c, "u16", n); - benchmark_all_equal::(c, "i16", n); - benchmark_all_equal::(c, "u32", n); - benchmark_all_equal::(c, "i32", n); - benchmark_all_equal::(c, "u64", n); - benchmark_all_equal::(c, "i64", n); - benchmark_all_equal::(c, "f32", n); - benchmark_all_equal::(c, "f64", n); - benchmark_all_equal::(c, "isize", n); - benchmark_all_equal::(c, "usize", n); - } + benchmark_all_equal::(c); + // benchmark_all_equal::(c); + // benchmark_all_equal::(c); + // benchmark_all_equal::(c, "i16", n); + // benchmark_all_equal::(c, "u32", n); + // benchmark_all_equal::(c, "i32", n); + // benchmark_all_equal::(c, "u64", n); + // benchmark_all_equal::(c, "i64", n); + // benchmark_all_equal::(c, "f32", n); + // benchmark_all_equal::(c, "f64", n); + // benchmark_all_equal::(c, "isize", n); + // benchmark_all_equal::(c, "usize", n); } criterion_group!(benches, criterion_benchmark); diff --git a/benches/contains.rs b/benches/contains.rs index 6878d98..6406510 100644 --- a/benches/contains.rs +++ b/benches/contains.rs @@ -1,79 +1,81 @@ -#![feature(portable_simd)] -#![feature(is_sorted)] -#![feature(sort_floats)] +// #![feature(portable_simd)] +// #![feature(is_sorted)] +// #![feature(sort_floats)] -use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use itertools::Itertools; -use simd_itertools::ContainsSimd; -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; +// use criterion::{black_box, criterion_group, criterion_main, Criterion}; +// use itertools::Itertools; +// use simd_itertools::ContainsSimd; +// 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 - T: SimdElement + std::cmp::PartialEq + TryFrom + Debug, - Simd: SimdPartialEq>, - >::Error: Debug, -{ - let v1 = vec![T::default(); len]; - let needle: T = 55.try_into().unwrap(); +// fn benchmark_contains<'a, T: 'static + Copy + PartialEq + Default + Debug>( +// _c: &mut Criterion, +// name: &str, +// len: usize, +// ) where +// T: SimdElement + std::cmp::PartialEq + TryFrom + Debug, +// Simd: SimdPartialEq>, +// >::Error: Debug, +// { +// let v1 = vec![T::default(); len]; +// let needle: T = 55.try_into().unwrap(); - let mut group = Criterion::default() - .warm_up_time(Duration::from_secs(1)) - .measurement_time(Duration::from_secs(1)); +// let mut group = Criterion::default() +// .warm_up_time(Duration::from_secs(1)) +// .measurement_time(Duration::from_secs(1)); - group.bench_function(&format!("SIMD contains {} {}", name, len), |b| { - b.iter(|| black_box(v1.iter().contains_simd(&needle))) - }); - group.bench_function(&format!("Scalar contains {} {}", name, len), |b| { - b.iter(|| black_box(v1.iter().contains(&needle))) - }); -} +// group.bench_function(&format!("SIMD contains {} {}", name, len), |b| { +// b.iter(|| black_box(v1.iter().contains_simd(&needle))) +// }); +// group.bench_function(&format!("Scalar contains {} {}", name, len), |b| { +// b.iter(|| black_box(v1.iter().contains(&needle))) +// }); +// } -fn benchmark_contains_floats<'a, T: 'static + Copy + PartialEq + Default + Debug>( - c: &mut Criterion, - name: &str, - len: usize, -) where - T: SimdElement + std::cmp::PartialEq + TryFrom + Debug + std::convert::From, - Simd: SimdPartialEq>, - >::Error: Debug, -{ - let v1 = vec![T::default(); len]; - let v2 = vec![T::default(); len]; - let needle: T = 55.0.try_into().unwrap(); - assert_eq!(v1, v2); +// fn benchmark_contains_floats<'a, T: 'static + Copy + PartialEq + Default + Debug>( +// c: &mut Criterion, +// name: &str, +// len: usize, +// ) where +// T: SimdElement + std::cmp::PartialEq + TryFrom + Debug + std::convert::From, +// Simd: SimdPartialEq>, +// >::Error: Debug, +// { +// let v1 = vec![T::default(); len]; +// let v2 = vec![T::default(); len]; +// let needle: T = 55.0.try_into().unwrap(); +// assert_eq!(v1, v2); - c.bench_function(&format!("SIMD contains {}", name), |b| { - b.iter(|| black_box(v1.iter().contains_simd(&needle))) - }); - c.bench_function(&format!("trivial contains {}", name), |b| { - b.iter(|| black_box(v1.iter().contains(&needle))) - }); -} +// c.bench_function(&format!("SIMD contains {}", name), |b| { +// b.iter(|| black_box(v1.iter().contains_simd(&needle))) +// }); +// c.bench_function(&format!("trivial contains {}", name), |b| { +// b.iter(|| black_box(v1.iter().contains(&needle))) +// }); +// } -fn criterion_benchmark(c: &mut Criterion) { - for n in (0..200).map(|x| x * 10) { - benchmark_contains::(c, "u8", n); - benchmark_contains::(c, "i8", n); - benchmark_contains::(c, "u16", n); - benchmark_contains::(c, "i16", n); - benchmark_contains::(c, "u32", n); - benchmark_contains::(c, "i32", n); - benchmark_contains::(c, "u64", n); - benchmark_contains::(c, "i64", n); - benchmark_contains::(c, "isize", n); - benchmark_contains::(c, "usize", n); - benchmark_contains_floats::(c, "f32", n); - benchmark_contains_floats::(c, "f64", n); - } -} +// fn criterion_benchmark(c: &mut Criterion) { +// for n in (0..200).map(|x| x * 10) { +// benchmark_contains::(c, "u8", n); +// benchmark_contains::(c, "i8", n); +// benchmark_contains::(c, "u16", n); +// benchmark_contains::(c, "i16", n); +// benchmark_contains::(c, "u32", n); +// benchmark_contains::(c, "i32", n); +// benchmark_contains::(c, "u64", n); +// benchmark_contains::(c, "i64", n); +// benchmark_contains::(c, "isize", n); +// benchmark_contains::(c, "usize", n); +// benchmark_contains_floats::(c, "f32", n); +// benchmark_contains_floats::(c, "f64", n); +// } +// } -criterion_group!(benches, criterion_benchmark); -criterion_main!(benches); +// criterion_group!(benches, criterion_benchmark); +// criterion_main!(benches); + +fn main() {} diff --git a/benches/eq.rs b/benches/eq.rs index 0c61cf5..09aacd4 100644 --- a/benches/eq.rs +++ b/benches/eq.rs @@ -1,52 +1,54 @@ -#![feature(portable_simd)] +// #![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; +// 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 - T: SimdElement + std::cmp::PartialEq, - Simd: SimdPartialEq>, -{ - let v1 = black_box(vec![T::default(); len]); - let v2 = black_box(vec![T::default(); len]); +// fn benchmark_contains<'a, T: 'static + Copy + PartialEq + Default + Debug>( +// _c: &mut Criterion, +// name: &str, +// len: usize, +// ) where +// T: SimdElement + std::cmp::PartialEq, +// Simd: SimdPartialEq>, +// { +// 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)); +// 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))) - }); -} +// 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))) +// }); +// } -fn criterion_benchmark(c: &mut Criterion) { - for n in (0..200).map(|x| x * 10) { - benchmark_contains::(c, "u8", n); - benchmark_contains::(c, "i8", n); - benchmark_contains::(c, "u16", n); - benchmark_contains::(c, "i16", n); - benchmark_contains::(c, "u32", n); - benchmark_contains::(c, "i32", n); - benchmark_contains::(c, "u64", n); - benchmark_contains::(c, "i64", n); - benchmark_contains::(c, "isize", n); - benchmark_contains::(c, "usize", n); - benchmark_contains::(c, "f32", n); - benchmark_contains::(c, "f64", n); - } -} -criterion_group!(benches, criterion_benchmark); -criterion_main!(benches); +// fn criterion_benchmark(c: &mut Criterion) { +// for n in (0..200).map(|x| x * 10) { +// benchmark_contains::(c, "u8", n); +// benchmark_contains::(c, "i8", n); +// benchmark_contains::(c, "u16", n); +// benchmark_contains::(c, "i16", n); +// benchmark_contains::(c, "u32", n); +// benchmark_contains::(c, "i32", n); +// benchmark_contains::(c, "u64", n); +// benchmark_contains::(c, "i64", n); +// benchmark_contains::(c, "isize", n); +// benchmark_contains::(c, "usize", n); +// benchmark_contains::(c, "f32", n); +// benchmark_contains::(c, "f64", n); +// } +// } +// criterion_group!(benches, criterion_benchmark); +// criterion_main!(benches); + +fn main() {} diff --git a/benches/filter.rs b/benches/filter.rs index 2325629..76f1a1e 100644 --- a/benches/filter.rs +++ b/benches/filter.rs @@ -1,55 +1,57 @@ -#![feature(portable_simd)] -#![feature(is_sorted)] -#![feature(sort_floats)] +// #![feature(portable_simd)] +// #![feature(is_sorted)] +// #![feature(sort_floats)] -use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use simd_itertools::FilterSimd; -use std::fmt::Debug; -use std::simd::cmp::SimdPartialOrd; -use std::simd::Mask; -use std::simd::{Simd, SimdElement}; -use std::time::Duration; +// use criterion::{black_box, criterion_group, criterion_main, Criterion}; +// use simd_itertools::FilterSimd; +// use std::fmt::Debug; +// use std::simd::cmp::SimdPartialOrd; +// 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 - T: SimdElement + std::cmp::PartialEq + TryFrom + Debug + PartialOrd, - Simd: SimdPartialOrd>, - >::Error: Debug, -{ - let v1 = vec![T::default(); len]; - let needle: T = 55.try_into().unwrap(); +// fn benchmark_contains<'a, T: 'static + Copy + PartialEq + Default + Debug>( +// _c: &mut Criterion, +// name: &str, +// len: usize, +// ) where +// T: SimdElement + std::cmp::PartialEq + TryFrom + Debug + PartialOrd, +// Simd: SimdPartialOrd>, +// >::Error: Debug, +// { +// let v1 = vec![T::default(); len]; +// let needle: T = 55.try_into().unwrap(); - let mut group = Criterion::default() - .warm_up_time(Duration::from_secs(1)) - .measurement_time(Duration::from_secs(1)); - group.bench_function(&format!("SIMD filter {} {}", name, len), |b| { - b.iter(|| black_box(v1.iter().filter_simd_lt(needle))) - }); - group.bench_function(&format!("Scalar filter {} {}", name, len), |b| { - b.iter(|| black_box(v1.iter().filter(|x| **x < needle))) - }); -} +// let mut group = Criterion::default() +// .warm_up_time(Duration::from_secs(1)) +// .measurement_time(Duration::from_secs(1)); +// group.bench_function(&format!("SIMD filter {} {}", name, len), |b| { +// b.iter(|| black_box(v1.iter().filter_simd_lt(needle))) +// }); +// group.bench_function(&format!("Scalar filter {} {}", name, len), |b| { +// b.iter(|| black_box(v1.iter().filter(|x| **x < needle))) +// }); +// } -fn criterion_benchmark(c: &mut Criterion) { - for n in (0..200).map(|x| x * 10) { - benchmark_contains::(c, "u8", n); - benchmark_contains::(c, "u16", n); - benchmark_contains::(c, "u32", n); - benchmark_contains::(c, "u64", n); - benchmark_contains::(c, "u8", n); - benchmark_contains::(c, "i8", n); - benchmark_contains::(c, "u16", n); - benchmark_contains::(c, "i16", n); - benchmark_contains::(c, "i32", n); - benchmark_contains::(c, "u64", n); - benchmark_contains::(c, "i64", n); - benchmark_contains::(c, "isize", n); - benchmark_contains::(c, "usize", n); - } -} +// fn criterion_benchmark(c: &mut Criterion) { +// for n in (0..200).map(|x| x * 10) { +// benchmark_contains::(c, "u8", n); +// benchmark_contains::(c, "u16", n); +// benchmark_contains::(c, "u32", n); +// benchmark_contains::(c, "u64", n); +// benchmark_contains::(c, "u8", n); +// benchmark_contains::(c, "i8", n); +// benchmark_contains::(c, "u16", n); +// benchmark_contains::(c, "i16", n); +// benchmark_contains::(c, "i32", n); +// benchmark_contains::(c, "u64", n); +// benchmark_contains::(c, "i64", n); +// benchmark_contains::(c, "isize", n); +// benchmark_contains::(c, "usize", n); +// } +// } -criterion_group!(benches, criterion_benchmark); -criterion_main!(benches); +// criterion_group!(benches, criterion_benchmark); +// criterion_main!(benches); + +fn main() {} diff --git a/benches/find.rs b/benches/find.rs index 322f248..074fd0a 100644 --- a/benches/find.rs +++ b/benches/find.rs @@ -1,80 +1,82 @@ -#![feature(portable_simd)] -#![feature(is_sorted)] -#![feature(sort_floats)] +// #![feature(portable_simd)] +// #![feature(is_sorted)] +// #![feature(sort_floats)] -use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use simd_itertools::FindSimd; -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; +// use criterion::{black_box, criterion_group, criterion_main, Criterion}; +// use simd_itertools::FindSimd; +// 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 - T: SimdElement + std::cmp::PartialEq + TryFrom + Debug, - Simd: SimdPartialEq>, - >::Error: Debug, -{ - let v1 = vec![T::default(); len]; - let needle: T = 55.try_into().unwrap(); +// fn benchmark_contains<'a, T: 'static + Copy + PartialEq + Default + Debug>( +// _c: &mut Criterion, +// name: &str, +// len: usize, +// ) where +// T: SimdElement + std::cmp::PartialEq + TryFrom + Debug, +// Simd: SimdPartialEq>, +// >::Error: Debug, +// { +// let v1 = vec![T::default(); len]; +// let needle: T = 55.try_into().unwrap(); - let mut group = Criterion::default() - .warm_up_time(Duration::from_secs(1)) - .measurement_time(Duration::from_secs(1)); - group.bench_function(&format!("SIMD find {}@{}", name, len), |b| { - b.iter(|| black_box(v1.iter().find_simd(needle))) - }); - group.bench_function(&format!("Scalar find {}@{}", name, len), |b| { - b.iter(|| black_box(v1.iter().find(|x| **x == needle))) - }); -} -fn benchmark_contains_floats<'a, T: 'static + Copy + PartialEq + Default + Debug>( - _c: &mut Criterion, - name: &str, - len: usize, -) where - T: SimdElement + std::cmp::PartialEq + TryFrom + Debug + std::convert::From, - Simd: SimdPartialEq>, - >::Error: Debug, -{ - let v1 = vec![T::default(); len]; - let v2 = vec![T::default(); len]; - let needle: T = 55.0.try_into().unwrap(); - assert_eq!(v1, v2); +// let mut group = Criterion::default() +// .warm_up_time(Duration::from_secs(1)) +// .measurement_time(Duration::from_secs(1)); +// group.bench_function(&format!("SIMD find {}@{}", name, len), |b| { +// b.iter(|| black_box(v1.iter().find_simd(needle))) +// }); +// group.bench_function(&format!("Scalar find {}@{}", name, len), |b| { +// b.iter(|| black_box(v1.iter().find(|x| **x == needle))) +// }); +// } +// fn benchmark_contains_floats<'a, T: 'static + Copy + PartialEq + Default + Debug>( +// _c: &mut Criterion, +// name: &str, +// len: usize, +// ) where +// T: SimdElement + std::cmp::PartialEq + TryFrom + Debug + std::convert::From, +// Simd: SimdPartialEq>, +// >::Error: Debug, +// { +// let v1 = vec![T::default(); len]; +// let v2 = vec![T::default(); len]; +// let needle: T = 55.0.try_into().unwrap(); +// assert_eq!(v1, v2); - let mut group = Criterion::default() - .warm_up_time(Duration::from_secs(1)) - .measurement_time(Duration::from_secs(1)); +// let mut group = Criterion::default() +// .warm_up_time(Duration::from_secs(1)) +// .measurement_time(Duration::from_secs(1)); - group.bench_function(&format!("SIMD find {} {}", name, len), |b| { - b.iter(|| black_box(v1.iter().find_simd(needle))) - }); - group.bench_function(&format!("Scalar find {} {}", name, len), |b| { - b.iter(|| black_box(v1.iter().find(|x| **x == needle))) - }); -} +// group.bench_function(&format!("SIMD find {} {}", name, len), |b| { +// b.iter(|| black_box(v1.iter().find_simd(needle))) +// }); +// group.bench_function(&format!("Scalar find {} {}", name, len), |b| { +// b.iter(|| black_box(v1.iter().find(|x| **x == needle))) +// }); +// } -fn criterion_benchmark(c: &mut Criterion) { - for n in (0..200).map(|x| x * 10) { - benchmark_contains::(c, "u8", n); - benchmark_contains::(c, "i8", n); - benchmark_contains::(c, "u16", n); - benchmark_contains::(c, "i16", n); - benchmark_contains::(c, "u32", n); - benchmark_contains::(c, "i32", n); - benchmark_contains::(c, "u64", n); - benchmark_contains::(c, "i64", n); - benchmark_contains::(c, "isize", n); - benchmark_contains::(c, "usize", n); - benchmark_contains_floats::(c, "f32", n); - benchmark_contains_floats::(c, "f64", n); - } -} +// fn criterion_benchmark(c: &mut Criterion) { +// for n in (0..200).map(|x| x * 10) { +// benchmark_contains::(c, "u8", n); +// benchmark_contains::(c, "i8", n); +// benchmark_contains::(c, "u16", n); +// benchmark_contains::(c, "i16", n); +// benchmark_contains::(c, "u32", n); +// benchmark_contains::(c, "i32", n); +// benchmark_contains::(c, "u64", n); +// benchmark_contains::(c, "i64", n); +// benchmark_contains::(c, "isize", n); +// benchmark_contains::(c, "usize", n); +// benchmark_contains_floats::(c, "f32", n); +// benchmark_contains_floats::(c, "f64", n); +// } +// } -criterion_group!(benches, criterion_benchmark); -criterion_main!(benches); +// criterion_group!(benches, criterion_benchmark); +// criterion_main!(benches); + +fn main() {} diff --git a/benches/is_sorted.rs b/benches/is_sorted.rs index 96e2ca1..bc96c33 100644 --- a/benches/is_sorted.rs +++ b/benches/is_sorted.rs @@ -1,54 +1,56 @@ -#![feature(portable_simd)] -#![feature(is_sorted)] +// #![feature(portable_simd)] +// #![feature(is_sorted)] -use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use simd_itertools::IsSortedSimd; -use simd_itertools::SIMD_LEN; -use std::fmt::Debug; -use std::simd::prelude::SimdPartialOrd; -use std::simd::Mask; -use std::simd::{Simd, SimdElement}; -use std::time::Duration; +// use criterion::{black_box, criterion_group, criterion_main, Criterion}; +// use simd_itertools::IsSortedSimd; +// use simd_itertools::SIMD_LEN; +// use std::fmt::Debug; +// use std::simd::prelude::SimdPartialOrd; +// 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 - T: SimdElement + std::cmp::PartialEq + Debug + std::cmp::PartialOrd, - Simd: SimdPartialOrd>, -{ - let v1 = vec![T::default(); len]; - let v2 = vec![T::default(); len]; - assert_eq!(v1, v2); +// fn benchmark_contains<'a, T: 'static + Copy + PartialEq + Default + Debug>( +// _c: &mut Criterion, +// name: &str, +// len: usize, +// ) where +// T: SimdElement + std::cmp::PartialEq + Debug + std::cmp::PartialOrd, +// Simd: SimdPartialOrd>, +// { +// let v1 = vec![T::default(); len]; +// let v2 = vec![T::default(); len]; +// assert_eq!(v1, v2); - let mut group = Criterion::default() - .warm_up_time(Duration::from_secs(1)) - .measurement_time(Duration::from_secs(1)); - group.bench_function(&format!("SIMD is_sorted {} {}", name, len), |b| { - b.iter(|| black_box(black_box(&v1).iter().is_sorted_simd())) - }); - group.bench_function(&format!("Scalar is_sorted {} {}", name, len), |b| { - b.iter(|| black_box(v1.iter().is_sorted())) - }); -} +// let mut group = Criterion::default() +// .warm_up_time(Duration::from_secs(1)) +// .measurement_time(Duration::from_secs(1)); +// group.bench_function(&format!("SIMD is_sorted {} {}", name, len), |b| { +// b.iter(|| black_box(black_box(&v1).iter().is_sorted_simd())) +// }); +// group.bench_function(&format!("Scalar is_sorted {} {}", name, len), |b| { +// b.iter(|| black_box(v1.iter().is_sorted())) +// }); +// } -fn criterion_benchmark(c: &mut Criterion) { - for n in (0..200).map(|x| x * 10) { - benchmark_contains::(c, "u8", n); - benchmark_contains::(c, "i8", n); - benchmark_contains::(c, "u16", n); - benchmark_contains::(c, "i16", n); - benchmark_contains::(c, "u32", n); - benchmark_contains::(c, "i32", n); - benchmark_contains::(c, "u64", n); - benchmark_contains::(c, "i64", n); - benchmark_contains::(c, "isize", n); - benchmark_contains::(c, "usize", n); - benchmark_contains::(c, "f32", n); - benchmark_contains::(c, "f64", n); - } -} +// fn criterion_benchmark(c: &mut Criterion) { +// for n in (0..200).map(|x| x * 10) { +// benchmark_contains::(c, "u8", n); +// benchmark_contains::(c, "i8", n); +// benchmark_contains::(c, "u16", n); +// benchmark_contains::(c, "i16", n); +// benchmark_contains::(c, "u32", n); +// benchmark_contains::(c, "i32", n); +// benchmark_contains::(c, "u64", n); +// benchmark_contains::(c, "i64", n); +// benchmark_contains::(c, "isize", n); +// benchmark_contains::(c, "usize", n); +// benchmark_contains::(c, "f32", n); +// benchmark_contains::(c, "f64", n); +// } +// } -criterion_group!(benches, criterion_benchmark); -criterion_main!(benches); +// criterion_group!(benches, criterion_benchmark); +// criterion_main!(benches); + +fn main() {} diff --git a/benches/max.rs b/benches/max.rs index e921fc4..823eaff 100644 --- a/benches/max.rs +++ b/benches/max.rs @@ -1,49 +1,51 @@ -#![feature(portable_simd)] -#![feature(is_sorted)] +// #![feature(portable_simd)] +// #![feature(is_sorted)] -use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use simd_itertools::MaxSimd; -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; +// use criterion::{black_box, criterion_group, criterion_main, Criterion}; +// use simd_itertools::MaxSimd; +// 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 - T: SimdElement + std::cmp::PartialEq + std::cmp::Ord, - Simd: SimdPartialEq>, -{ - let v1 = black_box(vec![T::default(); len]); +// fn benchmark_contains<'a, T: 'static + Copy + PartialEq + Default + Debug>( +// _c: &mut Criterion, +// name: &str, +// len: usize, +// ) where +// T: SimdElement + std::cmp::PartialEq + std::cmp::Ord, +// Simd: SimdPartialEq>, +// { +// let v1 = 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 max {} {}", name, len), |b| { - b.iter(|| black_box(black_box(&v1).iter().max_simd())) - }); - group.bench_function(&format!("Scalar max {} {}", name, len), |b| { - b.iter(|| black_box(v1.iter().max())) - }); -} +// let mut group = Criterion::default() +// .warm_up_time(Duration::from_secs(1)) +// .measurement_time(Duration::from_secs(1)); +// group.bench_function(&format!("SIMD max {} {}", name, len), |b| { +// b.iter(|| black_box(black_box(&v1).iter().max_simd())) +// }); +// group.bench_function(&format!("Scalar max {} {}", name, len), |b| { +// b.iter(|| black_box(v1.iter().max())) +// }); +// } -fn criterion_benchmark(c: &mut Criterion) { - for n in (0..200).map(|x| x * 10) { - benchmark_contains::(c, "u8", n); - benchmark_contains::(c, "i8", n); - benchmark_contains::(c, "u16", n); - benchmark_contains::(c, "i16", n); - benchmark_contains::(c, "u32", n); - benchmark_contains::(c, "i32", n); - benchmark_contains::(c, "u64", n); - benchmark_contains::(c, "i64", n); - benchmark_contains::(c, "isize", n); - benchmark_contains::(c, "usize", n); - } -} -criterion_group!(benches, criterion_benchmark); -criterion_main!(benches); +// fn criterion_benchmark(c: &mut Criterion) { +// for n in (0..200).map(|x| x * 10) { +// benchmark_contains::(c, "u8", n); +// benchmark_contains::(c, "i8", n); +// benchmark_contains::(c, "u16", n); +// benchmark_contains::(c, "i16", n); +// benchmark_contains::(c, "u32", n); +// benchmark_contains::(c, "i32", n); +// benchmark_contains::(c, "u64", n); +// benchmark_contains::(c, "i64", n); +// benchmark_contains::(c, "isize", n); +// benchmark_contains::(c, "usize", n); +// } +// } +// criterion_group!(benches, criterion_benchmark); +// criterion_main!(benches); + +fn main() {} diff --git a/benches/min.rs b/benches/min.rs index 7dcbfd0..26bad04 100644 --- a/benches/min.rs +++ b/benches/min.rs @@ -1,48 +1,50 @@ -#![feature(portable_simd)] +// #![feature(portable_simd)] -use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use simd_itertools::MinSimd; -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; +// use criterion::{black_box, criterion_group, criterion_main, Criterion}; +// use simd_itertools::MinSimd; +// 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 - T: SimdElement + std::cmp::PartialEq + std::cmp::Ord, - Simd: SimdPartialEq>, -{ - let v1 = black_box(vec![T::default(); len]); +// fn benchmark_contains<'a, T: 'static + Copy + PartialEq + Default + Debug>( +// _c: &mut Criterion, +// name: &str, +// len: usize, +// ) where +// T: SimdElement + std::cmp::PartialEq + std::cmp::Ord, +// Simd: SimdPartialEq>, +// { +// let v1 = 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 min {} {}", name, len), |b| { - b.iter(|| black_box(black_box(&v1).iter().min_simd())) - }); - group.bench_function(&format!("Scalar min {} {}", name, len), |b| { - b.iter(|| black_box(v1.iter().min())) - }); -} +// let mut group = Criterion::default() +// .warm_up_time(Duration::from_secs(1)) +// .measurement_time(Duration::from_secs(1)); +// group.bench_function(&format!("SIMD min {} {}", name, len), |b| { +// b.iter(|| black_box(black_box(&v1).iter().min_simd())) +// }); +// group.bench_function(&format!("Scalar min {} {}", name, len), |b| { +// b.iter(|| black_box(v1.iter().min())) +// }); +// } -fn criterion_benchmark(c: &mut Criterion) { - for n in (0..200).map(|x| x * 10) { - benchmark_contains::(c, "u8", n); - benchmark_contains::(c, "i8", n); - benchmark_contains::(c, "u16", n); - benchmark_contains::(c, "i16", n); - benchmark_contains::(c, "u32", n); - benchmark_contains::(c, "i32", n); - benchmark_contains::(c, "u64", n); - benchmark_contains::(c, "i64", n); - benchmark_contains::(c, "isize", n); - benchmark_contains::(c, "usize", n); - } -} -criterion_group!(benches, criterion_benchmark); -criterion_main!(benches); +// fn criterion_benchmark(c: &mut Criterion) { +// for n in (0..200).map(|x| x * 10) { +// benchmark_contains::(c, "u8", n); +// benchmark_contains::(c, "i8", n); +// benchmark_contains::(c, "u16", n); +// benchmark_contains::(c, "i16", n); +// benchmark_contains::(c, "u32", n); +// benchmark_contains::(c, "i32", n); +// benchmark_contains::(c, "u64", n); +// benchmark_contains::(c, "i64", n); +// benchmark_contains::(c, "isize", n); +// benchmark_contains::(c, "usize", n); +// } +// } +// criterion_group!(benches, criterion_benchmark); +// criterion_main!(benches); + +fn main() {} diff --git a/benches/position.rs b/benches/position.rs index d5fde9f..1771542 100644 --- a/benches/position.rs +++ b/benches/position.rs @@ -1,80 +1,82 @@ -#![feature(portable_simd)] -#![feature(is_sorted)] -#![feature(sort_floats)] +// #![feature(portable_simd)] +// #![feature(is_sorted)] +// #![feature(sort_floats)] -use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use simd_itertools::PositionSimd; -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; +// use criterion::{black_box, criterion_group, criterion_main, Criterion}; +// use simd_itertools::PositionSimd; +// 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 - T: SimdElement + std::cmp::PartialEq + TryFrom + Debug, - Simd: SimdPartialEq>, - >::Error: Debug, -{ - let v1 = vec![T::default(); len]; - let needle: T = 55.try_into().unwrap(); +// fn benchmark_contains<'a, T: 'static + Copy + PartialEq + Default + Debug>( +// _c: &mut Criterion, +// name: &str, +// len: usize, +// ) where +// T: SimdElement + std::cmp::PartialEq + TryFrom + Debug, +// Simd: SimdPartialEq>, +// >::Error: Debug, +// { +// let v1 = vec![T::default(); len]; +// let needle: T = 55.try_into().unwrap(); - let mut group = Criterion::default() - .warm_up_time(Duration::from_secs(1)) - .measurement_time(Duration::from_secs(1)); - group.bench_function(&format!("SIMD position {} {}", name, len), |b| { - b.iter(|| black_box(v1.iter().position_simd(needle))) - }); - group.bench_function(&format!("Scalar position {} {}", name, len), |b| { - b.iter(|| black_box(v1.iter().position(|x| *x == needle))) - }); -} -fn benchmark_contains_floats<'a, T: 'static + Copy + PartialEq + Default + Debug>( - _c: &mut Criterion, - name: &str, - len: usize, -) where - T: SimdElement + std::cmp::PartialEq + TryFrom + Debug + std::convert::From, - Simd: SimdPartialEq>, - >::Error: Debug, -{ - let v1 = vec![T::default(); len]; - let needle: T = 55.0.try_into().unwrap(); +// let mut group = Criterion::default() +// .warm_up_time(Duration::from_secs(1)) +// .measurement_time(Duration::from_secs(1)); +// group.bench_function(&format!("SIMD position {} {}", name, len), |b| { +// b.iter(|| black_box(v1.iter().position_simd(needle))) +// }); +// group.bench_function(&format!("Scalar position {} {}", name, len), |b| { +// b.iter(|| black_box(v1.iter().position(|x| *x == needle))) +// }); +// } +// fn benchmark_contains_floats<'a, T: 'static + Copy + PartialEq + Default + Debug>( +// _c: &mut Criterion, +// name: &str, +// len: usize, +// ) where +// T: SimdElement + std::cmp::PartialEq + TryFrom + Debug + std::convert::From, +// Simd: SimdPartialEq>, +// >::Error: Debug, +// { +// let v1 = vec![T::default(); len]; +// let needle: T = 55.0.try_into().unwrap(); - let mut group = Criterion::default() - .warm_up_time(Duration::from_secs(1)) - .measurement_time(Duration::from_secs(1)); +// let mut group = Criterion::default() +// .warm_up_time(Duration::from_secs(1)) +// .measurement_time(Duration::from_secs(1)); - group.bench_function(&format!("SIMD position {} {}", name, len), |b| { - b.iter(|| black_box(v1.iter().position_simd(needle))) - }); - group.bench_function(&format!("Scalar position {} {}", name, len), |b| { - b.iter(|| black_box(v1.iter().position(|x| *x == needle))) - }); -} +// group.bench_function(&format!("SIMD position {} {}", name, len), |b| { +// b.iter(|| black_box(v1.iter().position_simd(needle))) +// }); +// group.bench_function(&format!("Scalar position {} {}", name, len), |b| { +// b.iter(|| black_box(v1.iter().position(|x| *x == needle))) +// }); +// } -fn criterion_benchmark(c: &mut Criterion) { - for n in (0..200).map(|x| x * 10) { - benchmark_contains::(c, "u8", n); - benchmark_contains::(c, "u64", n); - benchmark_contains::(c, "u32", n); - benchmark_contains::(c, "u8", n); - benchmark_contains::(c, "i8", n); - benchmark_contains::(c, "u16", n); - benchmark_contains::(c, "i16", n); - benchmark_contains::(c, "i32", n); - benchmark_contains::(c, "u64", n); - benchmark_contains::(c, "i64", n); - benchmark_contains::(c, "isize", n); - benchmark_contains::(c, "usize", n); - benchmark_contains_floats::(c, "f32", n); - benchmark_contains_floats::(c, "f64", n); - } -} +// fn criterion_benchmark(c: &mut Criterion) { +// for n in (0..200).map(|x| x * 10) { +// benchmark_contains::(c, "u8", n); +// benchmark_contains::(c, "u64", n); +// benchmark_contains::(c, "u32", n); +// benchmark_contains::(c, "u8", n); +// benchmark_contains::(c, "i8", n); +// benchmark_contains::(c, "u16", n); +// benchmark_contains::(c, "i16", n); +// benchmark_contains::(c, "i32", n); +// benchmark_contains::(c, "u64", n); +// benchmark_contains::(c, "i64", n); +// benchmark_contains::(c, "isize", n); +// benchmark_contains::(c, "usize", n); +// benchmark_contains_floats::(c, "f32", n); +// benchmark_contains_floats::(c, "f64", n); +// } +// } -criterion_group!(benches, criterion_benchmark); -criterion_main!(benches); +// criterion_group!(benches, criterion_benchmark); +// criterion_main!(benches); + +fn main() {} From 7b6303dbc414e0d7e0f86bba61b344aecd692ac6 Mon Sep 17 00:00:00 2001 From: Saveliy Yusufov Date: Thu, 18 Jul 2024 16:48:00 -0400 Subject: [PATCH 02/12] Restructure `contains` benchmarks --- benches/contains.rs | 147 ++++++++++++++++++++++---------------------- benches/eq.rs | 96 ++++++++++++++--------------- 2 files changed, 122 insertions(+), 121 deletions(-) diff --git a/benches/contains.rs b/benches/contains.rs index 6406510..df5f381 100644 --- a/benches/contains.rs +++ b/benches/contains.rs @@ -1,81 +1,84 @@ -// #![feature(portable_simd)] -// #![feature(is_sorted)] -// #![feature(sort_floats)] +#![feature(portable_simd)] +#![feature(is_sorted)] +#![feature(sort_floats)] -// use criterion::{black_box, criterion_group, criterion_main, Criterion}; -// use itertools::Itertools; -// use simd_itertools::ContainsSimd; -// 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; +use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; +use itertools::Itertools; +use simd_itertools::{ContainsSimd, SIMD_LEN}; +use std::{ + fmt::Debug, + simd::{prelude::SimdPartialEq, Mask, Simd, SimdElement}, +}; -// fn benchmark_contains<'a, T: 'static + Copy + PartialEq + Default + Debug>( -// _c: &mut Criterion, -// name: &str, -// len: usize, -// ) where -// T: SimdElement + std::cmp::PartialEq + TryFrom + Debug, -// Simd: SimdPartialEq>, -// >::Error: Debug, -// { -// let v1 = vec![T::default(); len]; -// let needle: T = 55.try_into().unwrap(); +fn benchmark_contains<'a, T: 'static + Copy + PartialEq + Default + Debug>(c: &mut Criterion) +where + T: SimdElement + std::cmp::PartialEq + TryFrom + Debug, + Simd: SimdPartialEq>, + >::Error: Debug, +{ + let mut group = c.benchmark_group(format!("contains-{}", std::any::type_name::())); + let mut len = 1; -// let mut group = Criterion::default() -// .warm_up_time(Duration::from_secs(1)) -// .measurement_time(Duration::from_secs(1)); + while len < (1 << 11) { + let v1 = vec![T::default(); len]; + let needle: T = 55.try_into().unwrap(); -// group.bench_function(&format!("SIMD contains {} {}", name, len), |b| { -// b.iter(|| black_box(v1.iter().contains_simd(&needle))) -// }); -// group.bench_function(&format!("Scalar contains {} {}", name, len), |b| { -// b.iter(|| black_box(v1.iter().contains(&needle))) -// }); -// } + group.throughput(Throughput::Elements(len as u64)); -// fn benchmark_contains_floats<'a, T: 'static + Copy + PartialEq + Default + Debug>( -// c: &mut Criterion, -// name: &str, -// len: usize, -// ) where -// T: SimdElement + std::cmp::PartialEq + TryFrom + Debug + std::convert::From, -// Simd: SimdPartialEq>, -// >::Error: Debug, -// { -// let v1 = vec![T::default(); len]; -// let v2 = vec![T::default(); len]; -// let needle: T = 55.0.try_into().unwrap(); -// assert_eq!(v1, v2); + group.bench_function(BenchmarkId::new("SIMD", len), |b| { + b.iter(|| black_box(v1.iter().contains_simd(&needle))) + }); + group.bench_function(BenchmarkId::new("Scalar", len), |b| { + b.iter(|| black_box(v1.iter().contains(&needle))) + }); -// c.bench_function(&format!("SIMD contains {}", name), |b| { -// b.iter(|| black_box(v1.iter().contains_simd(&needle))) -// }); -// c.bench_function(&format!("trivial contains {}", name), |b| { -// b.iter(|| black_box(v1.iter().contains(&needle))) -// }); -// } + len *= 10; + } -// fn criterion_benchmark(c: &mut Criterion) { -// for n in (0..200).map(|x| x * 10) { -// benchmark_contains::(c, "u8", n); -// benchmark_contains::(c, "i8", n); -// benchmark_contains::(c, "u16", n); -// benchmark_contains::(c, "i16", n); -// benchmark_contains::(c, "u32", n); -// benchmark_contains::(c, "i32", n); -// benchmark_contains::(c, "u64", n); -// benchmark_contains::(c, "i64", n); -// benchmark_contains::(c, "isize", n); -// benchmark_contains::(c, "usize", n); -// benchmark_contains_floats::(c, "f32", n); -// benchmark_contains_floats::(c, "f64", n); -// } -// } + group.finish(); +} -// criterion_group!(benches, criterion_benchmark); -// criterion_main!(benches); +fn benchmark_contains_floats<'a, T: 'static + Copy + PartialEq + Default + Debug>(c: &mut Criterion) +where + T: SimdElement + std::cmp::PartialEq + TryFrom + Debug + std::convert::From, + Simd: SimdPartialEq>, + >::Error: Debug, +{ + let mut group = c.benchmark_group(format!("contains-float-{}", std::any::type_name::())); + let mut len = 1; -fn main() {} + while len < (1 << 11) { + let v1 = vec![T::default(); len]; + let v2 = vec![T::default(); len]; + let needle: T = 55.0.try_into().unwrap(); + assert_eq!(v1, v2); + + group.throughput(Throughput::Elements(len as u64)); + + group.bench_function(BenchmarkId::new("SIMD", len), |b| { + b.iter(|| black_box(v1.iter().contains_simd(&needle))) + }); + group.bench_function(BenchmarkId::new("Scalar", len), |b| { + b.iter(|| black_box(v1.iter().contains(&needle))) + }); + } + group.finish(); +} + +fn criterion_benchmark(c: &mut Criterion) { + benchmark_contains::(c); + benchmark_contains::(c); + benchmark_contains::(c); + benchmark_contains::(c); + benchmark_contains::(c); + benchmark_contains::(c); + benchmark_contains::(c); + benchmark_contains::(c); + benchmark_contains::(c); + benchmark_contains::(c); + benchmark_contains_floats::(c); + benchmark_contains_floats::(c); +} + +criterion_group!(benches, criterion_benchmark); +criterion_main!(benches); diff --git a/benches/eq.rs b/benches/eq.rs index 09aacd4..0c61cf5 100644 --- a/benches/eq.rs +++ b/benches/eq.rs @@ -1,54 +1,52 @@ -// #![feature(portable_simd)] +#![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; +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 -// T: SimdElement + std::cmp::PartialEq, -// Simd: SimdPartialEq>, -// { -// let v1 = black_box(vec![T::default(); len]); -// let v2 = black_box(vec![T::default(); len]); +fn benchmark_contains<'a, T: 'static + Copy + PartialEq + Default + Debug>( + _c: &mut Criterion, + name: &str, + len: usize, +) where + T: SimdElement + std::cmp::PartialEq, + Simd: SimdPartialEq>, +{ + 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)); + 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))) -// }); -// } + 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))) + }); +} -// fn criterion_benchmark(c: &mut Criterion) { -// for n in (0..200).map(|x| x * 10) { -// benchmark_contains::(c, "u8", n); -// benchmark_contains::(c, "i8", n); -// benchmark_contains::(c, "u16", n); -// benchmark_contains::(c, "i16", n); -// benchmark_contains::(c, "u32", n); -// benchmark_contains::(c, "i32", n); -// benchmark_contains::(c, "u64", n); -// benchmark_contains::(c, "i64", n); -// benchmark_contains::(c, "isize", n); -// benchmark_contains::(c, "usize", n); -// benchmark_contains::(c, "f32", n); -// benchmark_contains::(c, "f64", n); -// } -// } -// criterion_group!(benches, criterion_benchmark); -// criterion_main!(benches); - -fn main() {} +fn criterion_benchmark(c: &mut Criterion) { + for n in (0..200).map(|x| x * 10) { + benchmark_contains::(c, "u8", n); + benchmark_contains::(c, "i8", n); + benchmark_contains::(c, "u16", n); + benchmark_contains::(c, "i16", n); + benchmark_contains::(c, "u32", n); + benchmark_contains::(c, "i32", n); + benchmark_contains::(c, "u64", n); + benchmark_contains::(c, "i64", n); + benchmark_contains::(c, "isize", n); + benchmark_contains::(c, "usize", n); + benchmark_contains::(c, "f32", n); + benchmark_contains::(c, "f64", n); + } +} +criterion_group!(benches, criterion_benchmark); +criterion_main!(benches); From d3c54111f1f719708f403b2af7438929cbec6023 Mon Sep 17 00:00:00 2001 From: Saveliy Yusufov Date: Thu, 18 Jul 2024 17:00:01 -0400 Subject: [PATCH 03/12] Update eq benchmark using critertion structure --- benches/eq.rs | 83 ++++++++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/benches/eq.rs b/benches/eq.rs index 0c61cf5..da65b64 100644 --- a/benches/eq.rs +++ b/benches/eq.rs @@ -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: SimdPartialEq>, { - 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!("contains-{}", std::any::type_name::())); + 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::(c, "u8", n); - benchmark_contains::(c, "i8", n); - benchmark_contains::(c, "u16", n); - benchmark_contains::(c, "i16", n); - benchmark_contains::(c, "u32", n); - benchmark_contains::(c, "i32", n); - benchmark_contains::(c, "u64", n); - benchmark_contains::(c, "i64", n); - benchmark_contains::(c, "isize", n); - benchmark_contains::(c, "usize", n); - benchmark_contains::(c, "f32", n); - benchmark_contains::(c, "f64", n); - } + benchmark_eq::(c); + benchmark_eq::(c); + benchmark_eq::(c); + benchmark_eq::(c); + benchmark_eq::(c); + benchmark_eq::(c); + benchmark_eq::(c); + benchmark_eq::(c); + benchmark_eq::(c); + benchmark_eq::(c); + benchmark_eq::(c); + benchmark_eq::(c); } + criterion_group!(benches, criterion_benchmark); criterion_main!(benches); From 56d1501987416668c6b74e8ee46a1e416b1c970d Mon Sep 17 00:00:00 2001 From: Saveliy Yusufov Date: Thu, 18 Jul 2024 17:06:40 -0400 Subject: [PATCH 04/12] Restructure filter benchmark --- benches/contains.rs | 2 + benches/filter.rs | 112 ++++++++++++++++++++++---------------------- 2 files changed, 57 insertions(+), 57 deletions(-) diff --git a/benches/contains.rs b/benches/contains.rs index df5f381..9161511 100644 --- a/benches/contains.rs +++ b/benches/contains.rs @@ -61,6 +61,8 @@ where group.bench_function(BenchmarkId::new("Scalar", len), |b| { b.iter(|| black_box(v1.iter().contains(&needle))) }); + + len *= 10; } group.finish(); } diff --git a/benches/filter.rs b/benches/filter.rs index 76f1a1e..e7a9950 100644 --- a/benches/filter.rs +++ b/benches/filter.rs @@ -1,57 +1,55 @@ -// #![feature(portable_simd)] -// #![feature(is_sorted)] -// #![feature(sort_floats)] - -// use criterion::{black_box, criterion_group, criterion_main, Criterion}; -// use simd_itertools::FilterSimd; -// use std::fmt::Debug; -// use std::simd::cmp::SimdPartialOrd; -// 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 -// T: SimdElement + std::cmp::PartialEq + TryFrom + Debug + PartialOrd, -// Simd: SimdPartialOrd>, -// >::Error: Debug, -// { -// let v1 = vec![T::default(); len]; -// let needle: T = 55.try_into().unwrap(); - -// let mut group = Criterion::default() -// .warm_up_time(Duration::from_secs(1)) -// .measurement_time(Duration::from_secs(1)); -// group.bench_function(&format!("SIMD filter {} {}", name, len), |b| { -// b.iter(|| black_box(v1.iter().filter_simd_lt(needle))) -// }); -// group.bench_function(&format!("Scalar filter {} {}", name, len), |b| { -// b.iter(|| black_box(v1.iter().filter(|x| **x < needle))) -// }); -// } - -// fn criterion_benchmark(c: &mut Criterion) { -// for n in (0..200).map(|x| x * 10) { -// benchmark_contains::(c, "u8", n); -// benchmark_contains::(c, "u16", n); -// benchmark_contains::(c, "u32", n); -// benchmark_contains::(c, "u64", n); -// benchmark_contains::(c, "u8", n); -// benchmark_contains::(c, "i8", n); -// benchmark_contains::(c, "u16", n); -// benchmark_contains::(c, "i16", n); -// benchmark_contains::(c, "i32", n); -// benchmark_contains::(c, "u64", n); -// benchmark_contains::(c, "i64", n); -// benchmark_contains::(c, "isize", n); -// benchmark_contains::(c, "usize", n); -// } -// } - -// criterion_group!(benches, criterion_benchmark); -// criterion_main!(benches); - -fn main() {} +#![feature(portable_simd)] + +use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; +use simd_itertools::FilterSimd; +use std::{ + fmt::Debug, + simd::{cmp::SimdPartialOrd, Mask, Simd, SimdElement}, +}; + +fn benchmark_filter<'a, T: 'static + Copy + PartialEq + Default + Debug>(c: &mut Criterion) +where + T: SimdElement + std::cmp::PartialEq + TryFrom + Debug + PartialOrd, + Simd: SimdPartialOrd>, + >::Error: Debug, +{ + let mut group = c.benchmark_group(format!("all-equal-{}", std::any::type_name::())); + let mut len = 1; + + while len < (1 << 11) { + let v1 = vec![T::default(); len]; + let needle: T = 55.try_into().unwrap(); + + group.throughput(Throughput::Elements(len as u64)); + + group.bench_function(BenchmarkId::new("SIMD", len), |b| { + b.iter(|| black_box(v1.iter().filter_simd_lt(needle))) + }); + group.bench_function(BenchmarkId::new("Scalar", len), |b| { + b.iter(|| black_box(v1.iter().filter(|x| **x < needle))) + }); + + len *= 10; + } + + group.finish(); +} + +fn criterion_benchmark(c: &mut Criterion) { + benchmark_filter::(c); + benchmark_filter::(c); + benchmark_filter::(c); + benchmark_filter::(c); + benchmark_filter::(c); + benchmark_filter::(c); + benchmark_filter::(c); + benchmark_filter::(c); + benchmark_filter::(c); + benchmark_filter::(c); + benchmark_filter::(c); + benchmark_filter::(c); + benchmark_filter::(c); +} + +criterion_group!(benches, criterion_benchmark); +criterion_main!(benches); From 0acaf798e2215fd0493f40ae200336beded19c7d Mon Sep 17 00:00:00 2001 From: Saveliy Yusufov Date: Thu, 18 Jul 2024 18:36:48 -0400 Subject: [PATCH 05/12] Restructure benchmarks for find --- benches/filter.rs | 2 +- benches/find.rs | 150 +++++++++++++++++++++++----------------------- 2 files changed, 77 insertions(+), 75 deletions(-) diff --git a/benches/filter.rs b/benches/filter.rs index e7a9950..f19144e 100644 --- a/benches/filter.rs +++ b/benches/filter.rs @@ -13,7 +13,7 @@ where Simd: SimdPartialOrd>, >::Error: Debug, { - let mut group = c.benchmark_group(format!("all-equal-{}", std::any::type_name::())); + let mut group = c.benchmark_group(format!("filter-{}", std::any::type_name::())); let mut len = 1; while len < (1 << 11) { diff --git a/benches/find.rs b/benches/find.rs index 074fd0a..746f6b4 100644 --- a/benches/find.rs +++ b/benches/find.rs @@ -1,82 +1,84 @@ -// #![feature(portable_simd)] -// #![feature(is_sorted)] -// #![feature(sort_floats)] +#![feature(portable_simd)] +#![feature(is_sorted)] +#![feature(sort_floats)] -// use criterion::{black_box, criterion_group, criterion_main, Criterion}; -// use simd_itertools::FindSimd; -// 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; +use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; +use simd_itertools::{FindSimd, SIMD_LEN}; +use std::{ + fmt::Debug, + simd::{prelude::SimdPartialEq, Mask, Simd, SimdElement}, +}; -// fn benchmark_contains<'a, T: 'static + Copy + PartialEq + Default + Debug>( -// _c: &mut Criterion, -// name: &str, -// len: usize, -// ) where -// T: SimdElement + std::cmp::PartialEq + TryFrom + Debug, -// Simd: SimdPartialEq>, -// >::Error: Debug, -// { -// let v1 = vec![T::default(); len]; -// let needle: T = 55.try_into().unwrap(); +fn benchmark_find<'a, T: 'static + Copy + PartialEq + Default + Debug>(c: &mut Criterion) +where + T: SimdElement + std::cmp::PartialEq + TryFrom + Debug, + Simd: SimdPartialEq>, + >::Error: Debug, +{ + let mut group = c.benchmark_group(format!("find-{}", std::any::type_name::())); + let mut len = 1; -// let mut group = Criterion::default() -// .warm_up_time(Duration::from_secs(1)) -// .measurement_time(Duration::from_secs(1)); -// group.bench_function(&format!("SIMD find {}@{}", name, len), |b| { -// b.iter(|| black_box(v1.iter().find_simd(needle))) -// }); -// group.bench_function(&format!("Scalar find {}@{}", name, len), |b| { -// b.iter(|| black_box(v1.iter().find(|x| **x == needle))) -// }); -// } -// fn benchmark_contains_floats<'a, T: 'static + Copy + PartialEq + Default + Debug>( -// _c: &mut Criterion, -// name: &str, -// len: usize, -// ) where -// T: SimdElement + std::cmp::PartialEq + TryFrom + Debug + std::convert::From, -// Simd: SimdPartialEq>, -// >::Error: Debug, -// { -// let v1 = vec![T::default(); len]; -// let v2 = vec![T::default(); len]; -// let needle: T = 55.0.try_into().unwrap(); -// assert_eq!(v1, v2); + while len < (1 << 11) { + let v1 = vec![T::default(); len]; + let needle: T = 55.try_into().unwrap(); -// let mut group = Criterion::default() -// .warm_up_time(Duration::from_secs(1)) -// .measurement_time(Duration::from_secs(1)); + group.throughput(Throughput::Elements(len as u64)); -// group.bench_function(&format!("SIMD find {} {}", name, len), |b| { -// b.iter(|| black_box(v1.iter().find_simd(needle))) -// }); -// group.bench_function(&format!("Scalar find {} {}", name, len), |b| { -// b.iter(|| black_box(v1.iter().find(|x| **x == needle))) -// }); -// } + group.bench_function(BenchmarkId::new("SIMD", len), |b| { + b.iter(|| black_box(v1.iter().find_simd(needle))) + }); + group.bench_function(BenchmarkId::new("Scalar", len), |b| { + b.iter(|| black_box(v1.iter().find(|x| **x == needle))) + }); -// fn criterion_benchmark(c: &mut Criterion) { -// for n in (0..200).map(|x| x * 10) { -// benchmark_contains::(c, "u8", n); -// benchmark_contains::(c, "i8", n); -// benchmark_contains::(c, "u16", n); -// benchmark_contains::(c, "i16", n); -// benchmark_contains::(c, "u32", n); -// benchmark_contains::(c, "i32", n); -// benchmark_contains::(c, "u64", n); -// benchmark_contains::(c, "i64", n); -// benchmark_contains::(c, "isize", n); -// benchmark_contains::(c, "usize", n); -// benchmark_contains_floats::(c, "f32", n); -// benchmark_contains_floats::(c, "f64", n); -// } -// } + len *= 10; + } -// criterion_group!(benches, criterion_benchmark); -// criterion_main!(benches); + group.finish(); +} -fn main() {} +fn benchmark_find_float<'a, T: 'static + Copy + PartialEq + Default + Debug>(c: &mut Criterion) +where + T: SimdElement + std::cmp::PartialEq + TryFrom + Debug + std::convert::From, + Simd: SimdPartialEq>, + >::Error: Debug, +{ + let mut group = c.benchmark_group(format!("find-float-{}", std::any::type_name::())); + let mut len = 1; + + while len < (1 << 11) { + let v1 = vec![T::default(); len]; + let needle: T = (55.0).try_into().unwrap(); + + group.throughput(Throughput::Elements(len as u64)); + + group.bench_function(BenchmarkId::new("SIMD", len), |b| { + b.iter(|| black_box(v1.iter().find_simd(needle))) + }); + group.bench_function(BenchmarkId::new("Scalar", len), |b| { + b.iter(|| black_box(v1.iter().find(|x| **x == needle))) + }); + + len *= 10; + } + + group.finish(); +} + +fn criterion_benchmark(c: &mut Criterion) { + benchmark_find::(c); + benchmark_find::(c); + benchmark_find::(c); + benchmark_find::(c); + benchmark_find::(c); + benchmark_find::(c); + benchmark_find::(c); + benchmark_find::(c); + benchmark_find::(c); + benchmark_find::(c); + benchmark_find_float::(c); + benchmark_find_float::(c); +} + +criterion_group!(benches, criterion_benchmark); +criterion_main!(benches); From b867296701342684da47aa367b47f8f44f2022af Mon Sep 17 00:00:00 2001 From: Saveliy Yusufov Date: Thu, 18 Jul 2024 21:30:40 -0400 Subject: [PATCH 06/12] Restructure max and is_sorted benchmarks --- benches/is_sorted.rs | 109 ++++++++++++++++---------------- benches/max.rs | 103 +++++++++++++++--------------- benches/min.rs | 89 +++++++++++++------------- benches/position.rs | 147 +++++++++++++++++++++---------------------- 4 files changed, 220 insertions(+), 228 deletions(-) diff --git a/benches/is_sorted.rs b/benches/is_sorted.rs index bc96c33..7efd330 100644 --- a/benches/is_sorted.rs +++ b/benches/is_sorted.rs @@ -1,56 +1,53 @@ -// #![feature(portable_simd)] -// #![feature(is_sorted)] - -// use criterion::{black_box, criterion_group, criterion_main, Criterion}; -// use simd_itertools::IsSortedSimd; -// use simd_itertools::SIMD_LEN; -// use std::fmt::Debug; -// use std::simd::prelude::SimdPartialOrd; -// 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 -// T: SimdElement + std::cmp::PartialEq + Debug + std::cmp::PartialOrd, -// Simd: SimdPartialOrd>, -// { -// let v1 = vec![T::default(); len]; -// let v2 = vec![T::default(); len]; -// assert_eq!(v1, v2); - -// let mut group = Criterion::default() -// .warm_up_time(Duration::from_secs(1)) -// .measurement_time(Duration::from_secs(1)); -// group.bench_function(&format!("SIMD is_sorted {} {}", name, len), |b| { -// b.iter(|| black_box(black_box(&v1).iter().is_sorted_simd())) -// }); -// group.bench_function(&format!("Scalar is_sorted {} {}", name, len), |b| { -// b.iter(|| black_box(v1.iter().is_sorted())) -// }); -// } - -// fn criterion_benchmark(c: &mut Criterion) { -// for n in (0..200).map(|x| x * 10) { -// benchmark_contains::(c, "u8", n); -// benchmark_contains::(c, "i8", n); -// benchmark_contains::(c, "u16", n); -// benchmark_contains::(c, "i16", n); -// benchmark_contains::(c, "u32", n); -// benchmark_contains::(c, "i32", n); -// benchmark_contains::(c, "u64", n); -// benchmark_contains::(c, "i64", n); -// benchmark_contains::(c, "isize", n); -// benchmark_contains::(c, "usize", n); -// benchmark_contains::(c, "f32", n); -// benchmark_contains::(c, "f64", n); -// } -// } - -// criterion_group!(benches, criterion_benchmark); -// criterion_main!(benches); - -fn main() {} +#![feature(portable_simd)] +#![feature(is_sorted)] + +use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; +use simd_itertools::{IsSortedSimd, SIMD_LEN}; +use std::{ + fmt::Debug, + simd::{prelude::SimdPartialOrd, Mask, Simd, SimdElement}, +}; + +fn benchmark_is_sorted<'a, T: 'static + Copy + PartialEq + Default + Debug>(c: &mut Criterion) +where + T: SimdElement + std::cmp::PartialEq + Debug + std::cmp::PartialOrd, + Simd: SimdPartialOrd>, +{ + let mut group = c.benchmark_group(format!("is-sorted-{}", std::any::type_name::())); + let mut len = 1; + + while len < (1 << 11) { + let v1 = 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().is_sorted_simd())) + }); + group.bench_function(BenchmarkId::new("Scalar", len), |b| { + b.iter(|| black_box(v1.iter().is_sorted())) + }); + + len *= 10; + } + + group.finish(); +} + +fn criterion_benchmark(c: &mut Criterion) { + benchmark_is_sorted::(c); + benchmark_is_sorted::(c); + benchmark_is_sorted::(c); + benchmark_is_sorted::(c); + benchmark_is_sorted::(c); + benchmark_is_sorted::(c); + benchmark_is_sorted::(c); + benchmark_is_sorted::(c); + benchmark_is_sorted::(c); + benchmark_is_sorted::(c); + benchmark_is_sorted::(c); + benchmark_is_sorted::(c); +} + +criterion_group!(benches, criterion_benchmark); +criterion_main!(benches); diff --git a/benches/max.rs b/benches/max.rs index 823eaff..6ff379e 100644 --- a/benches/max.rs +++ b/benches/max.rs @@ -1,51 +1,52 @@ -// #![feature(portable_simd)] -// #![feature(is_sorted)] - -// use criterion::{black_box, criterion_group, criterion_main, Criterion}; -// use simd_itertools::MaxSimd; -// 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 -// T: SimdElement + std::cmp::PartialEq + std::cmp::Ord, -// Simd: SimdPartialEq>, -// { -// let v1 = 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 max {} {}", name, len), |b| { -// b.iter(|| black_box(black_box(&v1).iter().max_simd())) -// }); -// group.bench_function(&format!("Scalar max {} {}", name, len), |b| { -// b.iter(|| black_box(v1.iter().max())) -// }); -// } - -// fn criterion_benchmark(c: &mut Criterion) { -// for n in (0..200).map(|x| x * 10) { -// benchmark_contains::(c, "u8", n); -// benchmark_contains::(c, "i8", n); -// benchmark_contains::(c, "u16", n); -// benchmark_contains::(c, "i16", n); -// benchmark_contains::(c, "u32", n); -// benchmark_contains::(c, "i32", n); -// benchmark_contains::(c, "u64", n); -// benchmark_contains::(c, "i64", n); -// benchmark_contains::(c, "isize", n); -// benchmark_contains::(c, "usize", n); -// } -// } -// criterion_group!(benches, criterion_benchmark); -// criterion_main!(benches); - -fn main() {} +#![feature(portable_simd)] +#![feature(is_sorted)] + +use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; +use simd_itertools::{MaxSimd, SIMD_LEN}; +use std::{ + fmt::Debug, + simd::{prelude::SimdPartialEq, Mask, Simd, SimdElement}, +}; + +fn benchmark_max<'a, T: 'static + Copy + PartialEq + Default + Debug>(c: &mut Criterion) +where + T: SimdElement + std::cmp::PartialEq + std::cmp::Ord, + Simd: SimdPartialEq>, +{ + let mut group = c.benchmark_group(format!("max-{}", std::any::type_name::())); + let mut len = 1; + + while len < (1 << 11) { + let v1 = 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().max_simd())) + }); + group.bench_function(BenchmarkId::new("Scalar", len), |b| { + b.iter(|| black_box(v1.iter().max())) + }); + + len *= 10; + } + + group.finish(); +} + +fn criterion_benchmark(c: &mut Criterion) { + for n in (0..200).map(|x| x * 10) { + benchmark_max::(c); + benchmark_max::(c); + benchmark_max::(c); + benchmark_max::(c); + benchmark_max::(c); + benchmark_max::(c); + benchmark_max::(c); + benchmark_max::(c); + benchmark_max::(c); + benchmark_max::(c); + } +} +criterion_group!(benches, criterion_benchmark); +criterion_main!(benches); diff --git a/benches/min.rs b/benches/min.rs index 26bad04..4e1c95d 100644 --- a/benches/min.rs +++ b/benches/min.rs @@ -1,50 +1,47 @@ -// #![feature(portable_simd)] +#![feature(portable_simd)] -// use criterion::{black_box, criterion_group, criterion_main, Criterion}; -// use simd_itertools::MinSimd; -// 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; +use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use simd_itertools::{MinSimd, SIMD_LEN}; +use std::{ + fmt::Debug, + simd::{prelude::SimdPartialEq, Mask, Simd, SimdElement}, + time::Duration, +}; -// fn benchmark_contains<'a, T: 'static + Copy + PartialEq + Default + Debug>( -// _c: &mut Criterion, -// name: &str, -// len: usize, -// ) where -// T: SimdElement + std::cmp::PartialEq + std::cmp::Ord, -// Simd: SimdPartialEq>, -// { -// let v1 = black_box(vec![T::default(); len]); +fn benchmark_contains<'a, T: 'static + Copy + PartialEq + Default + Debug>( + _c: &mut Criterion, + name: &str, + len: usize, +) where + T: SimdElement + std::cmp::PartialEq + std::cmp::Ord, + Simd: SimdPartialEq>, +{ + let v1 = 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 min {} {}", name, len), |b| { -// b.iter(|| black_box(black_box(&v1).iter().min_simd())) -// }); -// group.bench_function(&format!("Scalar min {} {}", name, len), |b| { -// b.iter(|| black_box(v1.iter().min())) -// }); -// } + let mut group = Criterion::default() + .warm_up_time(Duration::from_secs(1)) + .measurement_time(Duration::from_secs(1)); + group.bench_function(&format!("SIMD min {} {}", name, len), |b| { + b.iter(|| black_box(black_box(&v1).iter().min_simd())) + }); + group.bench_function(&format!("Scalar min {} {}", name, len), |b| { + b.iter(|| black_box(v1.iter().min())) + }); +} -// fn criterion_benchmark(c: &mut Criterion) { -// for n in (0..200).map(|x| x * 10) { -// benchmark_contains::(c, "u8", n); -// benchmark_contains::(c, "i8", n); -// benchmark_contains::(c, "u16", n); -// benchmark_contains::(c, "i16", n); -// benchmark_contains::(c, "u32", n); -// benchmark_contains::(c, "i32", n); -// benchmark_contains::(c, "u64", n); -// benchmark_contains::(c, "i64", n); -// benchmark_contains::(c, "isize", n); -// benchmark_contains::(c, "usize", n); -// } -// } -// criterion_group!(benches, criterion_benchmark); -// criterion_main!(benches); - -fn main() {} +fn criterion_benchmark(c: &mut Criterion) { + for n in (0..200).map(|x| x * 10) { + benchmark_contains::(c, "u8", n); + benchmark_contains::(c, "i8", n); + benchmark_contains::(c, "u16", n); + benchmark_contains::(c, "i16", n); + benchmark_contains::(c, "u32", n); + benchmark_contains::(c, "i32", n); + benchmark_contains::(c, "u64", n); + benchmark_contains::(c, "i64", n); + benchmark_contains::(c, "isize", n); + benchmark_contains::(c, "usize", n); + } +} +criterion_group!(benches, criterion_benchmark); +criterion_main!(benches); diff --git a/benches/position.rs b/benches/position.rs index 1771542..0d8627e 100644 --- a/benches/position.rs +++ b/benches/position.rs @@ -1,82 +1,79 @@ -// #![feature(portable_simd)] -// #![feature(is_sorted)] -// #![feature(sort_floats)] +#![feature(portable_simd)] +#![feature(is_sorted)] +#![feature(sort_floats)] -// use criterion::{black_box, criterion_group, criterion_main, Criterion}; -// use simd_itertools::PositionSimd; -// 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; +use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use simd_itertools::{PositionSimd, SIMD_LEN}; +use std::{ + fmt::Debug, + simd::{prelude::SimdPartialEq, Mask, Simd, SimdElement}, + time::Duration, +}; -// fn benchmark_contains<'a, T: 'static + Copy + PartialEq + Default + Debug>( -// _c: &mut Criterion, -// name: &str, -// len: usize, -// ) where -// T: SimdElement + std::cmp::PartialEq + TryFrom + Debug, -// Simd: SimdPartialEq>, -// >::Error: Debug, -// { -// let v1 = vec![T::default(); len]; -// let needle: T = 55.try_into().unwrap(); +fn benchmark_contains<'a, T: 'static + Copy + PartialEq + Default + Debug>( + _c: &mut Criterion, + name: &str, + len: usize, +) where + T: SimdElement + std::cmp::PartialEq + TryFrom + Debug, + Simd: SimdPartialEq>, + >::Error: Debug, +{ + let v1 = vec![T::default(); len]; + let needle: T = 55.try_into().unwrap(); -// let mut group = Criterion::default() -// .warm_up_time(Duration::from_secs(1)) -// .measurement_time(Duration::from_secs(1)); -// group.bench_function(&format!("SIMD position {} {}", name, len), |b| { -// b.iter(|| black_box(v1.iter().position_simd(needle))) -// }); -// group.bench_function(&format!("Scalar position {} {}", name, len), |b| { -// b.iter(|| black_box(v1.iter().position(|x| *x == needle))) -// }); -// } -// fn benchmark_contains_floats<'a, T: 'static + Copy + PartialEq + Default + Debug>( -// _c: &mut Criterion, -// name: &str, -// len: usize, -// ) where -// T: SimdElement + std::cmp::PartialEq + TryFrom + Debug + std::convert::From, -// Simd: SimdPartialEq>, -// >::Error: Debug, -// { -// let v1 = vec![T::default(); len]; -// let needle: T = 55.0.try_into().unwrap(); + let mut group = Criterion::default() + .warm_up_time(Duration::from_secs(1)) + .measurement_time(Duration::from_secs(1)); + group.bench_function(&format!("SIMD position {} {}", name, len), |b| { + b.iter(|| black_box(v1.iter().position_simd(needle))) + }); + group.bench_function(&format!("Scalar position {} {}", name, len), |b| { + b.iter(|| black_box(v1.iter().position(|x| *x == needle))) + }); +} +fn benchmark_contains_floats<'a, T: 'static + Copy + PartialEq + Default + Debug>( + _c: &mut Criterion, + name: &str, + len: usize, +) where + T: SimdElement + std::cmp::PartialEq + TryFrom + Debug + std::convert::From, + Simd: SimdPartialEq>, + >::Error: Debug, +{ + let v1 = vec![T::default(); len]; + let needle: T = 55.0.try_into().unwrap(); -// let mut group = Criterion::default() -// .warm_up_time(Duration::from_secs(1)) -// .measurement_time(Duration::from_secs(1)); + let mut group = Criterion::default() + .warm_up_time(Duration::from_secs(1)) + .measurement_time(Duration::from_secs(1)); -// group.bench_function(&format!("SIMD position {} {}", name, len), |b| { -// b.iter(|| black_box(v1.iter().position_simd(needle))) -// }); -// group.bench_function(&format!("Scalar position {} {}", name, len), |b| { -// b.iter(|| black_box(v1.iter().position(|x| *x == needle))) -// }); -// } + group.bench_function(&format!("SIMD position {} {}", name, len), |b| { + b.iter(|| black_box(v1.iter().position_simd(needle))) + }); + group.bench_function(&format!("Scalar position {} {}", name, len), |b| { + b.iter(|| black_box(v1.iter().position(|x| *x == needle))) + }); +} -// fn criterion_benchmark(c: &mut Criterion) { -// for n in (0..200).map(|x| x * 10) { -// benchmark_contains::(c, "u8", n); -// benchmark_contains::(c, "u64", n); -// benchmark_contains::(c, "u32", n); -// benchmark_contains::(c, "u8", n); -// benchmark_contains::(c, "i8", n); -// benchmark_contains::(c, "u16", n); -// benchmark_contains::(c, "i16", n); -// benchmark_contains::(c, "i32", n); -// benchmark_contains::(c, "u64", n); -// benchmark_contains::(c, "i64", n); -// benchmark_contains::(c, "isize", n); -// benchmark_contains::(c, "usize", n); -// benchmark_contains_floats::(c, "f32", n); -// benchmark_contains_floats::(c, "f64", n); -// } -// } +fn criterion_benchmark(c: &mut Criterion) { + for n in (0..200).map(|x| x * 10) { + benchmark_contains::(c, "u8", n); + benchmark_contains::(c, "u64", n); + benchmark_contains::(c, "u32", n); + benchmark_contains::(c, "u8", n); + benchmark_contains::(c, "i8", n); + benchmark_contains::(c, "u16", n); + benchmark_contains::(c, "i16", n); + benchmark_contains::(c, "i32", n); + benchmark_contains::(c, "u64", n); + benchmark_contains::(c, "i64", n); + benchmark_contains::(c, "isize", n); + benchmark_contains::(c, "usize", n); + benchmark_contains_floats::(c, "f32", n); + benchmark_contains_floats::(c, "f64", n); + } +} -// criterion_group!(benches, criterion_benchmark); -// criterion_main!(benches); - -fn main() {} +criterion_group!(benches, criterion_benchmark); +criterion_main!(benches); From 49a278fc824e46228d70667cc4d228e1b9fe3544 Mon Sep 17 00:00:00 2001 From: Saveliy Yusufov Date: Thu, 18 Jul 2024 21:31:27 -0400 Subject: [PATCH 07/12] Remove outer loop in max benchmark --- benches/max.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/benches/max.rs b/benches/max.rs index 6ff379e..3d6916a 100644 --- a/benches/max.rs +++ b/benches/max.rs @@ -35,18 +35,16 @@ where } fn criterion_benchmark(c: &mut Criterion) { - for n in (0..200).map(|x| x * 10) { - benchmark_max::(c); - benchmark_max::(c); - benchmark_max::(c); - benchmark_max::(c); - benchmark_max::(c); - benchmark_max::(c); - benchmark_max::(c); - benchmark_max::(c); - benchmark_max::(c); - benchmark_max::(c); - } + benchmark_max::(c); + benchmark_max::(c); + benchmark_max::(c); + benchmark_max::(c); + benchmark_max::(c); + benchmark_max::(c); + benchmark_max::(c); + benchmark_max::(c); + benchmark_max::(c); + benchmark_max::(c); } criterion_group!(benches, criterion_benchmark); criterion_main!(benches); From e5798b00bcfa85402215b5b210062e666cbc325c Mon Sep 17 00:00:00 2001 From: Saveliy Yusufov Date: Thu, 18 Jul 2024 21:55:02 -0400 Subject: [PATCH 08/12] Restructure min benchmark --- benches/min.rs | 62 ++++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/benches/min.rs b/benches/min.rs index 4e1c95d..665b078 100644 --- a/benches/min.rs +++ b/benches/min.rs @@ -1,47 +1,49 @@ #![feature(portable_simd)] -use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; use simd_itertools::{MinSimd, SIMD_LEN}; use std::{ fmt::Debug, simd::{prelude::SimdPartialEq, Mask, Simd, SimdElement}, - time::Duration, }; -fn benchmark_contains<'a, T: 'static + Copy + PartialEq + Default + Debug>( - _c: &mut Criterion, - name: &str, - len: usize, -) where +fn benchmark_min<'a, T: 'static + Copy + PartialEq + Default + Debug>(c: &mut Criterion) +where T: SimdElement + std::cmp::PartialEq + std::cmp::Ord, Simd: SimdPartialEq>, { - let v1 = 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 min {} {}", name, len), |b| { - b.iter(|| black_box(black_box(&v1).iter().min_simd())) - }); - group.bench_function(&format!("Scalar min {} {}", name, len), |b| { - b.iter(|| black_box(v1.iter().min())) - }); + let mut group = c.benchmark_group(format!("max-{}", std::any::type_name::())); + let mut len = 1; + + while len < (1 << 11) { + let v1 = 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().min_simd())) + }); + group.bench_function(BenchmarkId::new("Scalar", len), |b| { + b.iter(|| black_box(v1.iter().min())) + }); + + len *= 10; + } + + group.finish(); } fn criterion_benchmark(c: &mut Criterion) { - for n in (0..200).map(|x| x * 10) { - benchmark_contains::(c, "u8", n); - benchmark_contains::(c, "i8", n); - benchmark_contains::(c, "u16", n); - benchmark_contains::(c, "i16", n); - benchmark_contains::(c, "u32", n); - benchmark_contains::(c, "i32", n); - benchmark_contains::(c, "u64", n); - benchmark_contains::(c, "i64", n); - benchmark_contains::(c, "isize", n); - benchmark_contains::(c, "usize", n); - } + benchmark_min::(c); + benchmark_min::(c); + benchmark_min::(c); + benchmark_min::(c); + benchmark_min::(c); + benchmark_min::(c); + benchmark_min::(c); + benchmark_min::(c); + benchmark_min::(c); + benchmark_min::(c); } criterion_group!(benches, criterion_benchmark); criterion_main!(benches); From 37c18eabcf2d365bff9fab4363cba54dd333f948 Mon Sep 17 00:00:00 2001 From: Saveliy Yusufov Date: Thu, 18 Jul 2024 22:00:14 -0400 Subject: [PATCH 09/12] Restructure position benchmark --- benches/position.rs | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/benches/position.rs b/benches/position.rs index 0d8627e..6d1e602 100644 --- a/benches/position.rs +++ b/benches/position.rs @@ -2,37 +2,41 @@ #![feature(is_sorted)] #![feature(sort_floats)] -use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; use simd_itertools::{PositionSimd, SIMD_LEN}; use std::{ fmt::Debug, simd::{prelude::SimdPartialEq, Mask, Simd, SimdElement}, - time::Duration, }; -fn benchmark_contains<'a, T: 'static + Copy + PartialEq + Default + Debug>( - _c: &mut Criterion, - name: &str, - len: usize, -) where +fn benchmark_position<'a, T: 'static + Copy + PartialEq + Default + Debug>(c: &mut Criterion) +where T: SimdElement + std::cmp::PartialEq + TryFrom + Debug, Simd: SimdPartialEq>, >::Error: Debug, { - let v1 = vec![T::default(); len]; - let needle: T = 55.try_into().unwrap(); + let mut group = c.benchmark_group(format!("max-{}", std::any::type_name::())); + let mut len = 1; - let mut group = Criterion::default() - .warm_up_time(Duration::from_secs(1)) - .measurement_time(Duration::from_secs(1)); - group.bench_function(&format!("SIMD position {} {}", name, len), |b| { - b.iter(|| black_box(v1.iter().position_simd(needle))) - }); - group.bench_function(&format!("Scalar position {} {}", name, len), |b| { - b.iter(|| black_box(v1.iter().position(|x| *x == needle))) - }); + while len < (1 << 11) { + let v1 = vec![T::default(); len]; + let needle: T = 55.try_into().unwrap(); + + group.throughput(Throughput::Elements(len as u64)); + + group.bench_function(BenchmarkId::new("SIMD", len), |b| { + b.iter(|| black_box(v1.iter().position_simd(needle))) + }); + group.bench_function(BenchmarkId::new("Scalar", len), |b| { + b.iter(|| black_box(v1.iter().position(|x| *x == needle))) + }); + + len *= 10; + } + + group.finish(); } -fn benchmark_contains_floats<'a, T: 'static + Copy + PartialEq + Default + Debug>( +fn benchmark_position_floats<'a, T: 'static + Copy + PartialEq + Default + Debug>( _c: &mut Criterion, name: &str, len: usize, From 4a93dd3dcccc34926dd6bde410186a3f8d9fabcb Mon Sep 17 00:00:00 2001 From: Saveliy Yusufov Date: Thu, 18 Jul 2024 22:04:00 -0400 Subject: [PATCH 10/12] Fix position and min benchmarks --- benches/min.rs | 2 +- benches/position.rs | 67 ++++++++++++++++++++++++--------------------- 2 files changed, 37 insertions(+), 32 deletions(-) diff --git a/benches/min.rs b/benches/min.rs index 665b078..6e0cc82 100644 --- a/benches/min.rs +++ b/benches/min.rs @@ -12,7 +12,7 @@ where T: SimdElement + std::cmp::PartialEq + std::cmp::Ord, Simd: SimdPartialEq>, { - let mut group = c.benchmark_group(format!("max-{}", std::any::type_name::())); + let mut group = c.benchmark_group(format!("min-{}", std::any::type_name::())); let mut len = 1; while len < (1 << 11) { diff --git a/benches/position.rs b/benches/position.rs index 6d1e602..4cffa11 100644 --- a/benches/position.rs +++ b/benches/position.rs @@ -15,7 +15,7 @@ where Simd: SimdPartialEq>, >::Error: Debug, { - let mut group = c.benchmark_group(format!("max-{}", std::any::type_name::())); + let mut group = c.benchmark_group(format!("position-{}", std::any::type_name::())); let mut len = 1; while len < (1 << 11) { @@ -36,46 +36,51 @@ where group.finish(); } -fn benchmark_position_floats<'a, T: 'static + Copy + PartialEq + Default + Debug>( - _c: &mut Criterion, - name: &str, - len: usize, -) where + +fn benchmark_position_floats<'a, T: 'static + Copy + PartialEq + Default + Debug>(c: &mut Criterion) +where T: SimdElement + std::cmp::PartialEq + TryFrom + Debug + std::convert::From, Simd: SimdPartialEq>, >::Error: Debug, { - let v1 = vec![T::default(); len]; - let needle: T = 55.0.try_into().unwrap(); + let mut group = c.benchmark_group(format!("position-floats-{}", std::any::type_name::())); + let mut len = 1; + + while len < (1 << 11) { + let v1 = vec![T::default(); len]; + let needle: T = (55.0).try_into().unwrap(); + + group.throughput(Throughput::Elements(len as u64)); + + group.bench_function(BenchmarkId::new("SIMD", len), |b| { + b.iter(|| black_box(v1.iter().position_simd(needle))) + }); + group.bench_function(BenchmarkId::new("Scalar", len), |b| { + b.iter(|| black_box(v1.iter().position(|x| *x == needle))) + }); - let mut group = Criterion::default() - .warm_up_time(Duration::from_secs(1)) - .measurement_time(Duration::from_secs(1)); + len *= 10; + } - group.bench_function(&format!("SIMD position {} {}", name, len), |b| { - b.iter(|| black_box(v1.iter().position_simd(needle))) - }); - group.bench_function(&format!("Scalar position {} {}", name, len), |b| { - b.iter(|| black_box(v1.iter().position(|x| *x == needle))) - }); + group.finish(); } fn criterion_benchmark(c: &mut Criterion) { for n in (0..200).map(|x| x * 10) { - benchmark_contains::(c, "u8", n); - benchmark_contains::(c, "u64", n); - benchmark_contains::(c, "u32", n); - benchmark_contains::(c, "u8", n); - benchmark_contains::(c, "i8", n); - benchmark_contains::(c, "u16", n); - benchmark_contains::(c, "i16", n); - benchmark_contains::(c, "i32", n); - benchmark_contains::(c, "u64", n); - benchmark_contains::(c, "i64", n); - benchmark_contains::(c, "isize", n); - benchmark_contains::(c, "usize", n); - benchmark_contains_floats::(c, "f32", n); - benchmark_contains_floats::(c, "f64", n); + benchmark_position::(c); + benchmark_position::(c); + benchmark_position::(c); + benchmark_position::(c); + benchmark_position::(c); + benchmark_position::(c); + benchmark_position::(c); + benchmark_position::(c); + benchmark_position::(c); + benchmark_position::(c); + benchmark_position::(c); + benchmark_position::(c); + benchmark_position_floats::(c); + benchmark_position_floats::(c); } } From 6d317d600853b4dc65fd0f74ce40f0376ada87df Mon Sep 17 00:00:00 2001 From: Saveliy Yusufov Date: Thu, 18 Jul 2024 22:11:50 -0400 Subject: [PATCH 11/12] Remove outer for loop for position benchmark --- benches/position.rs | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/benches/position.rs b/benches/position.rs index 4cffa11..1cdd3f9 100644 --- a/benches/position.rs +++ b/benches/position.rs @@ -66,22 +66,20 @@ where } fn criterion_benchmark(c: &mut Criterion) { - for n in (0..200).map(|x| x * 10) { - benchmark_position::(c); - benchmark_position::(c); - benchmark_position::(c); - benchmark_position::(c); - benchmark_position::(c); - benchmark_position::(c); - benchmark_position::(c); - benchmark_position::(c); - benchmark_position::(c); - benchmark_position::(c); - benchmark_position::(c); - benchmark_position::(c); - benchmark_position_floats::(c); - benchmark_position_floats::(c); - } + benchmark_position::(c); + benchmark_position::(c); + benchmark_position::(c); + benchmark_position::(c); + benchmark_position::(c); + benchmark_position::(c); + benchmark_position::(c); + benchmark_position::(c); + benchmark_position::(c); + benchmark_position::(c); + benchmark_position::(c); + benchmark_position::(c); + benchmark_position_floats::(c); + benchmark_position_floats::(c); } criterion_group!(benches, criterion_benchmark); From 79152ebc6baf7c4b4e5bc5dab9bd0e4b56cfae78 Mon Sep 17 00:00:00 2001 From: Saveliy Yusufov Date: Thu, 18 Jul 2024 23:03:41 -0400 Subject: [PATCH 12/12] Fix all_equal benchmark name --- benches/all_equal.rs | 22 +++++++++++----------- benches/eq.rs | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/benches/all_equal.rs b/benches/all_equal.rs index eca9b95..fd92edc 100644 --- a/benches/all_equal.rs +++ b/benches/all_equal.rs @@ -37,17 +37,17 @@ where fn criterion_benchmark(c: &mut Criterion) { benchmark_all_equal::(c); - // benchmark_all_equal::(c); - // benchmark_all_equal::(c); - // benchmark_all_equal::(c, "i16", n); - // benchmark_all_equal::(c, "u32", n); - // benchmark_all_equal::(c, "i32", n); - // benchmark_all_equal::(c, "u64", n); - // benchmark_all_equal::(c, "i64", n); - // benchmark_all_equal::(c, "f32", n); - // benchmark_all_equal::(c, "f64", n); - // benchmark_all_equal::(c, "isize", n); - // benchmark_all_equal::(c, "usize", n); + benchmark_all_equal::(c); + benchmark_all_equal::(c); + benchmark_all_equal::(c); + benchmark_all_equal::(c); + benchmark_all_equal::(c); + benchmark_all_equal::(c); + benchmark_all_equal::(c); + benchmark_all_equal::(c); + benchmark_all_equal::(c); + benchmark_all_equal::(c); + benchmark_all_equal::(c); } criterion_group!(benches, criterion_benchmark); diff --git a/benches/eq.rs b/benches/eq.rs index da65b64..10c47e9 100644 --- a/benches/eq.rs +++ b/benches/eq.rs @@ -12,7 +12,7 @@ where T: SimdElement + std::cmp::PartialEq, Simd: SimdPartialEq>, { - let mut group = c.benchmark_group(format!("contains-{}", std::any::type_name::())); + let mut group = c.benchmark_group(format!("eq-{}", std::any::type_name::())); let mut len = 1; while len < (1 << 11) {