From a712e8fb1cebaa39508a04dc4ba97eae12ba9dcd Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Wed, 10 Jan 2024 17:14:08 +0100 Subject: [PATCH] multi input benchmark --- members/revsqrt/benches/rsqrt-bench.rs | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/members/revsqrt/benches/rsqrt-bench.rs b/members/revsqrt/benches/rsqrt-bench.rs index 6f81e90..5982390 100644 --- a/members/revsqrt/benches/rsqrt-bench.rs +++ b/members/revsqrt/benches/rsqrt-bench.rs @@ -1,11 +1,31 @@ #![allow(unused)] -use criterion::{black_box, criterion_group, criterion_main, Criterion, BenchmarkId}; +use criterion::{black_box, criterion_group, criterion_main, Criterion, BenchmarkId, Throughput}; use revsqrt::{inverse_sqrt, fast_inverse_sqrt}; const SIZE: f32 = 1337.1337; -pub fn criterion_benchmark(c: &mut Criterion) { +const FCONST: f32 = 1024.12481224; +const FCONST1: f32 = 4025.724812234; +pub fn single_input(c: &mut Criterion) { c.bench_with_input(BenchmarkId::new("regular rsqrt", SIZE),&SIZE, |b, &s| b.iter(|| inverse_sqrt(s))); c.bench_with_input(BenchmarkId::new("fast rsqrt", SIZE),&SIZE, |b, &s| b.iter(|| fast_inverse_sqrt(s))); } -criterion_group!(benches, criterion_benchmark); +pub fn multi_input(c: &mut Criterion) { + let mut group = c.benchmark_group("multi_input"); + for size in [FCONST, 2.2 * FCONST, 4.24 * FCONST, 8.64 * FCONST, 16.12 * FCONST].iter() { + group.throughput(Throughput::Bytes(*size as u64)); + group.bench_with_input(BenchmarkId::new("regular rsqrt mixed input", FCONST), size, |b, &size| { + b.iter(||inverse_sqrt(size)); + }); + } + for size in [FCONST1, 2.2 * FCONST1, 4.24 * FCONST1, 8.64 * FCONST1, 16.12 * FCONST1].iter() { + group.throughput(Throughput::Bytes(*size as u64)); + group.bench_with_input(BenchmarkId::new("fast rsqrt mixed input", FCONST1), size, |b, &size| { + b.iter(||fast_inverse_sqrt(size)); + }); + } + group.finish(); +} + + +criterion_group!(benches, single_input, multi_input); criterion_main!(benches);