use std::{hint::black_box, time::{Duration, Instant}}; #[inline(never)] fn generate_samples(input: &[f64; 256], iterations: usize) -> f64 { let mut last = 0.0; for _ in 0..iterations { for x in input { let x = black_box(*x); last = black_box(match OP { 0 => x, 1 => x.exp2(), 2 => x.tan(), _ => 1.0 / x, }); } } last } fn run(lo: f64, hi: f64) { let input = std::array::from_fn(|i| lo + (hi - lo) * i as f64 / 255.0); let started = Instant::now(); while started.elapsed() < Duration::from_millis(100) { black_box(generate_samples::(&input, 1024)); } let count = 32768; let started = Instant::now(); let last = generate_samples::(&input, count); let duration = started.elapsed().as_nanos(); println!("{} {} {}", duration, count * 256, last.to_bits()); } fn main() { let case = std::env::args().nth(1).unwrap(); match case.as_str() { "identity" => run::<0>(2.0, 3.0), "exp2-pad" => run::<1>(2.0, 3.0), "exp2-range" => run::<1>(-2.0, 12.0), "tan-pad" => run::<2>(0.02, 0.25), "tan-range" => run::<2>(0.001, 1.4247585730565963), "reciprocal" => run::<3>(0.5, 10.0), _ => panic!("unknown case"), } }