Being new to benchmarking, will the following code will actually reveal the knowledge I seek – *Which std method is a faster way of determining if two floating point values have the same sign?*

```
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
// use num_traits::{float::Float};
use rand::{thread_rng, Rng};
type Pair = (f64, f64);
#[inline]
/// I think this will be slower because it includes a copysign call
/// ^ I was wrong
fn compare_same_signum(test_pairs: &[Pair]) {
test_pairs
.iter()
.for_each(|(a, b)| {
let _ = a.signum() == b.signum();
});
}
#[inline]
/// I think this will be faster because there's no copysign call
/// ^ I was wrong
fn compare_same_is_sign(test_pairs: &[Pair]) {
test_pairs
.iter()
.for_each(|(a, b)| {
let _ = a.is_sign_negative() == b.is_sign_negative();
});
}
#[inline]
/// I think this will maybe be on par with the is_sign methods which use to_bits
/// ^ I was kind of right
fn compare_same_to_bits(test_pairs: &[Pair]) {
let mask = 0x8000_0000_0000_0000u64;
test_pairs
.iter()
.for_each(|(a,b)| {
let _ = (a.to_bits() & b.to_bits()) & mask != 0;
});
}
fn bench_float_comparisons(c: &mut Criterion) {
// Some random test data
let mut rng = thread_rng();
let test_size = 100_000_000usize;
let test_pairs = (0..test_size)
.map(|_| (rng.gen(), rng.gen()))
.collect::<Vec<Pair>>();
// A benchmarking group
let mut group = c.benchmark_group("float sign comparisons");
// Comparisons on differently-logarithmic-decade-sized slices of the same random test data
for i in (1..8).rev().map(|d| test_size/10usize.pow(d)) {
group.bench_with_input(
BenchmarkId::new("signum", i),
&i,
|b, i| b.iter(|| {
compare_same_signum(&test_pairs[0..*i])
})
);
group.bench_with_input(
BenchmarkId::new("is_sign_negative", i),
&i,
|b, i| b.iter(|| {
compare_same_is_sign(&test_pairs[0..*i])
})
);
group.bench_with_input(
BenchmarkId::new("to_bits", i),
&i,
|b, i| b.iter(|| {
compare_same_to_bits(&test_pairs[0..*i])
})
);
}
group.finish();
}
criterion_group!(benches, bench_float_comparisons);
criterion_main!(benches);
```

Is there a more accurate way to do this? Do you see any major issues with the way I write the benchmark?

*Unnecessary background information:*

I am partially doing this to learn to benchmark properly/accurately before I try benchmarking larger code sections that rely on the similar operations to classify points, vectors, etc that are known to be finite – otherwise I'd just stick to `signum`

.

I ran the code a few times, but after viewing the results, my brain has neither grown any larger nor gained heightened powers of perception.