aboutsummaryrefslogtreecommitdiff
path: root/benches/convert.rs
diff options
context:
space:
mode:
Diffstat (limited to 'benches/convert.rs')
-rw-r--r--benches/convert.rs282
1 files changed, 145 insertions, 137 deletions
diff --git a/benches/convert.rs b/benches/convert.rs
index 4801c8d..53bae70 100644
--- a/benches/convert.rs
+++ b/benches/convert.rs
@@ -1,87 +1,91 @@
-use criterion::{criterion_group, criterion_main, Bencher, Criterion};
+use criterion::{criterion_group, criterion_main, Bencher, BenchmarkId, Criterion};
use half::prelude::*;
use std::{f32, f64, iter};
const SIMD_LARGE_BENCH_SLICE_LEN: usize = 1024;
fn bench_f32_to_f16(c: &mut Criterion) {
- c.bench_function_over_inputs(
- "f16::from_f32",
- |b: &mut Bencher<'_>, i: &f32| b.iter(|| f16::from_f32(*i)),
- vec![
- 0.,
- -0.,
- 1.,
- f32::MIN,
- f32::MAX,
- f32::MIN_POSITIVE,
- f32::NEG_INFINITY,
- f32::INFINITY,
- f32::NAN,
- f32::consts::E,
- f32::consts::PI,
- ],
- );
+ let mut group = c.benchmark_group("Convert f16 From f32");
+ for val in &[
+ 0.,
+ -0.,
+ 1.,
+ f32::MIN,
+ f32::MAX,
+ f32::MIN_POSITIVE,
+ f32::NEG_INFINITY,
+ f32::INFINITY,
+ f32::NAN,
+ f32::consts::E,
+ f32::consts::PI,
+ ] {
+ group.bench_with_input(BenchmarkId::new("f16::from_f32", val), val, |b, i| {
+ b.iter(|| f16::from_f32(*i))
+ });
+ }
}
fn bench_f64_to_f16(c: &mut Criterion) {
- c.bench_function_over_inputs(
- "f16::from_f64",
- |b: &mut Bencher<'_>, i: &f64| b.iter(|| f16::from_f64(*i)),
- vec![
- 0.,
- -0.,
- 1.,
- f64::MIN,
- f64::MAX,
- f64::MIN_POSITIVE,
- f64::NEG_INFINITY,
- f64::INFINITY,
- f64::NAN,
- f64::consts::E,
- f64::consts::PI,
- ],
- );
+ let mut group = c.benchmark_group("Convert f16 From f64");
+ for val in &[
+ 0.,
+ -0.,
+ 1.,
+ f64::MIN,
+ f64::MAX,
+ f64::MIN_POSITIVE,
+ f64::NEG_INFINITY,
+ f64::INFINITY,
+ f64::NAN,
+ f64::consts::E,
+ f64::consts::PI,
+ ] {
+ group.bench_with_input(BenchmarkId::new("f16::from_f64", val), val, |b, i| {
+ b.iter(|| f16::from_f64(*i))
+ });
+ }
}
fn bench_f16_to_f32(c: &mut Criterion) {
- c.bench_function_over_inputs(
- "f16::to_f32",
- |b: &mut Bencher<'_>, i: &f16| b.iter(|| i.to_f32()),
- vec![
- f16::ZERO,
- f16::NEG_ZERO,
- f16::ONE,
- f16::MIN,
- f16::MAX,
- f16::MIN_POSITIVE,
- f16::NEG_INFINITY,
- f16::INFINITY,
- f16::NAN,
- f16::E,
- f16::PI,
- ],
- );
+ let mut group = c.benchmark_group("Convert f16 to f32");
+ for val in &[
+ f16::ZERO,
+ f16::NEG_ZERO,
+ f16::ONE,
+ f16::MIN,
+ f16::MAX,
+ f16::MIN_POSITIVE,
+ f16::NEG_INFINITY,
+ f16::INFINITY,
+ f16::NAN,
+ f16::E,
+ f16::PI,
+ ] {
+ group.bench_with_input(BenchmarkId::new("f16::to_f32", val), val, |b, i| {
+ b.iter(|| i.to_f32())
+ });
+ }
}
fn bench_f16_to_f64(c: &mut Criterion) {
- c.bench_function_over_inputs(
- "f16::to_f64",
- |b: &mut Bencher<'_>, i: &f16| b.iter(|| i.to_f64()),
- vec![
- f16::ZERO,
- f16::NEG_ZERO,
- f16::ONE,
- f16::MIN,
- f16::MAX,
- f16::MIN_POSITIVE,
- f16::NEG_INFINITY,
- f16::INFINITY,
- f16::NAN,
- f16::E,
- f16::PI,
- ],
- );
+ let mut group = c.benchmark_group("Convert f16 to f64");
+ for val in &[
+ f16::ZERO,
+ f16::NEG_ZERO,
+ f16::ONE,
+ f16::MIN,
+ f16::MAX,
+ f16::MIN_POSITIVE,
+ f16::NEG_INFINITY,
+ f16::INFINITY,
+ f16::NAN,
+ f16::E,
+ f16::PI,
+ ] {
+ group.bench_with_input(BenchmarkId::new("f16::to_f64", val), val, |b, i| {
+ b.iter(|| i.to_f64())
+ });
+ }
}
criterion_group!(
@@ -229,83 +233,87 @@ criterion_group!(
);
fn bench_f32_to_bf16(c: &mut Criterion) {
- c.bench_function_over_inputs(
- "bf16::from_f32",
- |b: &mut Bencher<'_>, i: &f32| b.iter(|| bf16::from_f32(*i)),
- vec![
- 0.,
- -0.,
- 1.,
- f32::MIN,
- f32::MAX,
- f32::MIN_POSITIVE,
- f32::NEG_INFINITY,
- f32::INFINITY,
- f32::NAN,
- f32::consts::E,
- f32::consts::PI,
- ],
- );
+ let mut group = c.benchmark_group("Convert bf16 From f32");
+ for val in &[
+ 0.,
+ -0.,
+ 1.,
+ f32::MIN,
+ f32::MAX,
+ f32::MIN_POSITIVE,
+ f32::NEG_INFINITY,
+ f32::INFINITY,
+ f32::NAN,
+ f32::consts::E,
+ f32::consts::PI,
+ ] {
+ group.bench_with_input(BenchmarkId::new("bf16::from_f32", val), val, |b, i| {
+ b.iter(|| bf16::from_f32(*i))
+ });
+ }
}
fn bench_f64_to_bf16(c: &mut Criterion) {
- c.bench_function_over_inputs(
- "bf16::from_f64",
- |b: &mut Bencher<'_>, i: &f64| b.iter(|| bf16::from_f64(*i)),
- vec![
- 0.,
- -0.,
- 1.,
- f64::MIN,
- f64::MAX,
- f64::MIN_POSITIVE,
- f64::NEG_INFINITY,
- f64::INFINITY,
- f64::NAN,
- f64::consts::E,
- f64::consts::PI,
- ],
- );
+ let mut group = c.benchmark_group("Convert bf16 From f64");
+ for val in &[
+ 0.,
+ -0.,
+ 1.,
+ f64::MIN,
+ f64::MAX,
+ f64::MIN_POSITIVE,
+ f64::NEG_INFINITY,
+ f64::INFINITY,
+ f64::NAN,
+ f64::consts::E,
+ f64::consts::PI,
+ ] {
+ group.bench_with_input(BenchmarkId::new("bf16::from_f64", val), val, |b, i| {
+ b.iter(|| bf16::from_f64(*i))
+ });
+ }
}
fn bench_bf16_to_f32(c: &mut Criterion) {
- c.bench_function_over_inputs(
- "bf16::to_f32",
- |b: &mut Bencher<'_>, i: &bf16| b.iter(|| i.to_f32()),
- vec![
- bf16::ZERO,
- bf16::NEG_ZERO,
- bf16::ONE,
- bf16::MIN,
- bf16::MAX,
- bf16::MIN_POSITIVE,
- bf16::NEG_INFINITY,
- bf16::INFINITY,
- bf16::NAN,
- bf16::E,
- bf16::PI,
- ],
- );
+ let mut group = c.benchmark_group("Convert bf16 to f32");
+ for val in &[
+ bf16::ZERO,
+ bf16::NEG_ZERO,
+ bf16::ONE,
+ bf16::MIN,
+ bf16::MAX,
+ bf16::MIN_POSITIVE,
+ bf16::NEG_INFINITY,
+ bf16::INFINITY,
+ bf16::NAN,
+ bf16::E,
+ bf16::PI,
+ ] {
+ group.bench_with_input(BenchmarkId::new("bf16::to_f32", val), val, |b, i| {
+ b.iter(|| i.to_f32())
+ });
+ }
}
fn bench_bf16_to_f64(c: &mut Criterion) {
- c.bench_function_over_inputs(
- "bf16::to_f64",
- |b: &mut Bencher<'_>, i: &bf16| b.iter(|| i.to_f64()),
- vec![
- bf16::ZERO,
- bf16::NEG_ZERO,
- bf16::ONE,
- bf16::MIN,
- bf16::MAX,
- bf16::MIN_POSITIVE,
- bf16::NEG_INFINITY,
- bf16::INFINITY,
- bf16::NAN,
- bf16::E,
- bf16::PI,
- ],
- );
+ let mut group = c.benchmark_group("Convert bf16 to f64");
+ for val in &[
+ bf16::ZERO,
+ bf16::NEG_ZERO,
+ bf16::ONE,
+ bf16::MIN,
+ bf16::MAX,
+ bf16::MIN_POSITIVE,
+ bf16::NEG_INFINITY,
+ bf16::INFINITY,
+ bf16::NAN,
+ bf16::E,
+ bf16::PI,
+ ] {
+ group.bench_with_input(BenchmarkId::new("bf16::to_f64", val), val, |b, i| {
+ b.iter(|| i.to_f64())
+ });
+ }
}
criterion_group!(