rs-basic/members/revsqrt/benches/rsqrt-bench.rs

59 lines
1.6 KiB
Rust
Raw Normal View History

2024-01-10 16:53:47 +01:00
#![allow(unused)]
2024-01-10 21:24:00 +01:00
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
2024-01-11 11:46:34 +01:00
use revsqrt::{fast_inverse_sqrt, regular_inverse_sqrt};
2024-01-10 16:53:47 +01:00
const SIZE: f32 = 1337.1337;
2024-01-10 17:14:08 +01:00
const FCONST: f32 = 1024.12481224;
const FCONST1: f32 = 4025.724812234;
pub fn single_input(c: &mut Criterion) {
2024-01-10 21:24:00 +01:00
c.bench_with_input(BenchmarkId::new("regular rsqrt", SIZE), &SIZE, |b, &s| {
2024-01-11 11:46:34 +01:00
b.iter(|| regular_inverse_sqrt(s))
2024-01-10 21:24:00 +01:00
});
c.bench_with_input(BenchmarkId::new("fast rsqrt", SIZE), &SIZE, |b, &s| {
b.iter(|| fast_inverse_sqrt(s))
});
2024-01-10 16:53:47 +01:00
}
2024-01-10 17:14:08 +01:00
pub fn multi_input(c: &mut Criterion) {
let mut group = c.benchmark_group("multi_input");
2024-01-10 21:24:00 +01:00
for size in [
FCONST,
2.2 * FCONST,
4.24 * FCONST,
8.64 * FCONST,
16.12 * FCONST,
]
.iter()
{
2024-01-10 17:14:08 +01:00
group.throughput(Throughput::Bytes(*size as u64));
2024-01-10 21:24:00 +01:00
group.bench_with_input(
BenchmarkId::new("regular rsqrt mixed input", FCONST),
size,
|b, &size| {
2024-01-11 11:46:34 +01:00
b.iter(|| regular_inverse_sqrt(size));
2024-01-10 21:24:00 +01:00
},
);
2024-01-10 17:14:08 +01:00
}
2024-01-10 21:24:00 +01:00
for size in [
FCONST1,
2.2 * FCONST1,
4.24 * FCONST1,
8.64 * FCONST1,
16.12 * FCONST1,
]
.iter()
{
2024-01-10 17:14:08 +01:00
group.throughput(Throughput::Bytes(*size as u64));
2024-01-10 21:24:00 +01:00
group.bench_with_input(
BenchmarkId::new("fast rsqrt mixed input", FCONST1),
size,
|b, &size| {
b.iter(|| fast_inverse_sqrt(size));
},
);
2024-01-10 17:14:08 +01:00
}
group.finish();
}
criterion_group!(benches, single_input, multi_input);
2024-01-10 16:53:47 +01:00
criterion_main!(benches);