#![allow(dead_code)]
use computable::{Binary, Computable, XUsize};
use criterion::BenchmarkId;
const STANDARD_BITS: &[usize] = &[1, 4, 16, 64, 256];
const EXTENDED_BITS: &[usize] = &[1, 4, 16, 64, 256, 1024, 2048, 4096, 8192];
pub fn precision_bits() -> &'static [usize] {
if high_precision() {
EXTENDED_BITS
} else {
STANDARD_BITS
}
}
pub fn high_precision() -> bool {
std::env::var("BENCH_HIGH_PRECISION").is_ok()
}
pub fn epsilon(bits: usize) -> XUsize {
XUsize::Finite(bits)
}
pub fn bench_id(bits: impl std::fmt::Display) -> BenchmarkId {
BenchmarkId::from_parameter(format!("precision-{bits}"))
}
pub fn bench_id_named(name: impl Into<String>, bits: impl std::fmt::Display) -> BenchmarkId {
BenchmarkId::new(name, format!("precision-{bits}"))
}
pub fn verbose() -> bool {
std::env::var("BENCH_VERBOSE").is_ok()
}
pub fn balanced_sum(mut values: Vec<Computable>) -> Computable {
if values.is_empty() {
return Computable::constant(Binary::zero());
}
while values.len() > 1 {
let mut next = Vec::with_capacity(values.len().div_ceil(2));
let mut iter = values.into_iter();
while let Some(left) = iter.next() {
if let Some(right) = iter.next() {
next.push(left + right);
} else {
next.push(left);
}
}
values = next;
}
values
.pop()
.expect("values should contain at least one element")
}