use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; use fast_fp::{ff32, FF32}; use rand::{distributions::Standard, thread_rng, Rng}; fn sum(c: &mut Criterion) { let mut group = c.benchmark_group("sum"); for count in [2, 4, 8, 16, 64, 1024, 1 << 15] { group.throughput(Throughput::Elements(count as u64)); let f32_vals = thread_rng() .sample_iter(Standard) .take(count) .collect::>(); // use the same values for both benchmarks let ff32_vals = f32_vals .clone() .into_iter() .map(ff32) .collect::>(); group.bench_with_input(BenchmarkId::new("std::f32", count), &f32_vals, |b, vals| { b.iter(|| vals.iter().copied().fold(0.0, |acc, val| acc + val)); }); group.bench_with_input(BenchmarkId::new("FF32", count), &ff32_vals, |b, vals| { b.iter(|| vals.iter().copied().fold(ff32(0.0), |acc, val| acc + val)); }); } group.finish(); } criterion_group!(benches, sum); criterion_main!(benches);