This commit is contained in:
Renar Narubin
2021-11-05 14:47:17 -07:00
parent ea523d8f67
commit 2c77c05dff
2 changed files with 241 additions and 180 deletions

View File

@@ -1,5 +1,5 @@
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use fast_fp::{ff32, FF32};
use fast_fp::{ff32, ff64, FF32, FF64};
use rand::{distributions::Standard, thread_rng, Rng};
fn sum(c: &mut Criterion) {
@@ -26,6 +26,26 @@ fn sum(c: &mut Criterion) {
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));
});
let f64_vals = thread_rng()
.sample_iter(Standard)
.take(count)
.collect::<Vec<f64>>();
// use the same values for both benchmarks
let ff64_vals = f64_vals
.clone()
.into_iter()
.map(ff64)
.collect::<Vec<FF64>>();
group.bench_with_input(BenchmarkId::new("std::f64", count), &f64_vals, |b, vals| {
b.iter(|| vals.iter().copied().fold(0.0, |acc, val| acc + val));
});
group.bench_with_input(BenchmarkId::new("FF64", count), &ff64_vals, |b, vals| {
b.iter(|| vals.iter().copied().fold(ff64(0.0), |acc, val| acc + val));
});
}
group.finish();
}