use codspeed_criterion_compat::{BenchmarkId, Criterion, criterion_group, criterion_main};
use std::hint::black_box;

use sqpack_rs::hash::{crc32, hash_index1_key, hash_index2};

const SHORT_PATH: &str = "exd/root.exl";

const LONG_PATH: &str = "chara/monster/m0001/obj/body/b0001/material/mt_m0001b0001_a_very_long_material_subname_padding_padding_padding_padding_padding_padding_padding_padding_padding_padding_padding.mtrl";

fn bench_hash(c: &mut Criterion) {
    let mut group = c.benchmark_group("hash");

    group.bench_with_input(BenchmarkId::new("crc32", "short"), &SHORT_PATH, |b, p| {
        b.iter(|| crc32(black_box(p.as_bytes())));
    });
    group.bench_with_input(BenchmarkId::new("crc32", "long"), &LONG_PATH, |b, p| {
        b.iter(|| crc32(black_box(p.as_bytes())));
    });

    group.bench_with_input(
        BenchmarkId::new("hash_index1_key", "short"),
        &SHORT_PATH,
        |b, p| {
            b.iter(|| hash_index1_key(black_box(p)));
        },
    );
    group.bench_with_input(
        BenchmarkId::new("hash_index1_key", "long"),
        &LONG_PATH,
        |b, p| {
            b.iter(|| hash_index1_key(black_box(p)));
        },
    );

    group.bench_with_input(
        BenchmarkId::new("hash_index2", "short"),
        &SHORT_PATH,
        |b, p| {
            b.iter(|| hash_index2(black_box(p)));
        },
    );
    group.bench_with_input(
        BenchmarkId::new("hash_index2", "long"),
        &LONG_PATH,
        |b, p| {
            b.iter(|| hash_index2(black_box(p)));
        },
    );

    group.finish();
}

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