Improve readme, ditch features, don't impl Float

This commit is contained in:
Renar Narubin
2021-12-20 21:47:30 -08:00
parent 63647ad28d
commit 36605ab399
8 changed files with 126 additions and 218 deletions

View File

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

View File

@@ -3,12 +3,12 @@ use criterion::{
BenchmarkId, Criterion, Throughput,
};
use fast_fp::{ff32, ff64, FF32, FF64};
use ops::{Add, Div, Mul};
use rand::{
distributions::{self, Distribution},
rngs::StdRng,
Rng, SeedableRng,
};
use std::ops::{Add, Div, Mul};
fn add(c: &mut Criterion) {
let mut group = c.benchmark_group("add");
@@ -18,9 +18,9 @@ fn add(c: &mut Criterion) {
let f64s = distributions::Uniform::<f64>::new(0.0, 1.0);
// clone the rng for each benched type to keep the generated values identical
fold(&mut group, "std::f32", f32::add, 0.0, rng.clone(), f32s);
fold(&mut group, "f32", f32::add, 0.0, rng.clone(), f32s);
fold(&mut group, "FF32", FF32::add, ff32(0.0), rng.clone(), f32s);
fold(&mut group, "std::f64", f64::add, 0.0, rng.clone(), f64s);
fold(&mut group, "f64", f64::add, 0.0, rng.clone(), f64s);
fold(&mut group, "FF64", FF64::add, ff64(0.0), rng.clone(), f64s);
}
@@ -34,9 +34,9 @@ fn mul(c: &mut Criterion) {
let f64s = distributions::Uniform::<f64>::new(0.9, 1.1);
// clone the rng for each benched type to keep the generated values identical
fold(&mut group, "std::f32", f32::mul, 0.0, rng.clone(), f32s);
fold(&mut group, "f32", f32::mul, 0.0, rng.clone(), f32s);
fold(&mut group, "FF32", FF32::mul, ff32(0.0), rng.clone(), f32s);
fold(&mut group, "std::f64", f64::mul, 0.0, rng.clone(), f64s);
fold(&mut group, "f64", f64::mul, 0.0, rng.clone(), f64s);
fold(&mut group, "FF64", FF64::mul, ff64(0.0), rng.clone(), f64s);
}
@@ -50,9 +50,9 @@ fn div(c: &mut Criterion) {
let f64s = distributions::Uniform::<f64>::new(0.9, 1.1);
// clone the rng for each benched type to keep the generated values identical
fold(&mut group, "std::f32", f32::div, 0.0, rng.clone(), f32s);
fold(&mut group, "f32", f32::div, 0.0, rng.clone(), f32s);
fold(&mut group, "FF32", FF32::div, ff32(0.0), rng.clone(), f32s);
fold(&mut group, "std::f64", f64::div, 0.0, rng.clone(), f64s);
fold(&mut group, "f64", f64::div, 0.0, rng.clone(), f64s);
fold(&mut group, "FF64", FF64::div, ff64(0.0), rng.clone(), f64s);
}
@@ -64,9 +64,9 @@ fn min(c: &mut Criterion) {
let f64s = distributions::Uniform::<f64>::new(0.0, 1.0);
// clone the rng for each benched type to keep the generated values identical
fold(&mut group, "std::f32", f32::min, 0.0, rng.clone(), f32s);
fold(&mut group, "f32", f32::min, 0.0, rng.clone(), f32s);
fold(&mut group, "FF32", FF32::min, ff32(0.0), rng.clone(), f32s);
fold(&mut group, "std::f64", f64::min, 0.0, rng.clone(), f64s);
fold(&mut group, "f64", f64::min, 0.0, rng.clone(), f64s);
fold(&mut group, "FF64", FF64::min, ff64(0.0), rng.clone(), f64s);
}