// Throughput benchmark for base36 encoding
// This benchmark measures the raw encoding throughput similar to the old CLI command
// Run with: cargo bench --bench base36_throughput

use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use wasot_compiler::base36::u64_to_base36;

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

    // Test various batch sizes to measure throughput
    for size in [1_000, 10_000, 100_000, 1_000_000].iter() {
        group.throughput(Throughput::Elements(*size as u64));
        group.bench_with_input(BenchmarkId::from_parameter(size), size, |b, &size| {
            b.iter(|| {
                for i in 0..size {
                    let _ = black_box(u64_to_base36(black_box(i as u64)));
                }
            });
        });
    }
    group.finish();

    // Single element encode benchmark for precise timing
    c.bench_function("base36_encode_single", |b| {
        let mut counter = 0u64;
        b.iter(|| {
            counter = counter.wrapping_add(1);
            black_box(u64_to_base36(black_box(counter)))
        });
    });

    // Test with edge cases
    c.bench_function("base36_encode_zero", |b| {
        b.iter(|| black_box(u64_to_base36(black_box(0))));
    });

    c.bench_function("base36_encode_max", |b| {
        b.iter(|| black_box(u64_to_base36(black_box(u64::MAX))));
    });
}

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