extern crate concision as cnc;
use cnc::Params;
use cnc::init::NdRandom;
use core::hint::black_box;
use criterion::{BatchSize, BenchmarkId, Criterion};
use ndarray::Array1;
const SAMPLES: usize = 50;
const DEFAULT_DURATION_SECS: u64 = 10;
fn bench_params_forward(c: &mut Criterion) {
let mut group = c.benchmark_group("Params");
group.measurement_time(std::time::Duration::from_secs(DEFAULT_DURATION_SECS));
group.sample_size(SAMPLES);
for &n in &[10, 50, 100, 500, 1000] {
group.bench_with_input(BenchmarkId::new("Params::forward", n), &n, |b, &x| {
b.iter_batched(
|| {
let params = Params::<f64>::glorot_normal((n, 64));
let x = Array1::<f64>::linspace(0.0, 1.0, x);
(params, x)
},
|(params, x)| {
black_box(params.forward(&x));
},
BatchSize::SmallInput,
);
});
}
group.finish();
}
criterion::criterion_group! {
benches,
bench_params_forward,
}
criterion::criterion_main! {
benches
}