use criterion::{criterion_group, criterion_main, Criterion, black_box};
use sav::{mkA, A};

fn iota_rs(x: usize) -> Vec<usize> {
    (0..x).collect::<Vec<_>>()
}

fn cutC<X>(x: &[X], w: u32) -> Vec<Vec<X>>
where
    X: Copy,
{
    let w = w as usize;
    let L = x.len();
    let mut it = x.into_iter();
    let mut i = 0;
    let mut r = Vec::new();

    while (i * w) + w <= L {
        let row = it.by_ref().take(w).copied().collect::<Vec<_>>();
        r.push(row);
        i += 1;
    }

    r
}

pub fn bench(c: &mut Criterion) {
    let iotaN = 1_000_000;

    c.bench_function("big iota", |b| b.iter(|| A::A::iota(black_box(iotaN))));

    let iota = A::A::iota(iotaN);
    let big = 100;
    let small = 5;
    c.bench_function("big cut", |b| b.iter(|| iota.cutC(black_box(big))));
    c.bench_function("small cut", |b| b.iter(|| iota.cutC(black_box(small))));

    let iota = iota_rs(iotaN);
    c.bench_function("Vec big cut", |b| b.iter(|| cutC(&iota, black_box(big))));
    c.bench_function("Vec small cut", |b| b.iter(|| cutC(&iota, black_box(small))));
}

criterion_group!(benches, bench);
criterion_main!(benches);

