use criterion::{black_box, criterion_group, criterion_main, Criterion};
use stream_server::streaming::protocols::http_range::ByteRange;
use std::str::FromStr;

fn bench_parse_range(c: &mut Criterion) {
    c.bench_function("parse_exact_range", |b| {
        b.iter(|| {
            ByteRange::from_str(black_box("bytes=0-499")).unwrap();
        })
    });

    c.bench_function("parse_suffix_range", |b| {
        b.iter(|| {
            ByteRange::from_str(black_box("bytes=-500")).unwrap();
        })
    });

    c.bench_function("parse_from_range", |b| {
        b.iter(|| {
            ByteRange::from_str(black_box("bytes=1000-")).unwrap();
        })
    });
}

fn bench_resolve_range(c: &mut Criterion) {
    let range = ByteRange::Exact(1000, 2000);
    let file_size = 5000;

    c.bench_function("resolve_range", |b| {
        b.iter(|| {
            range.resolve(black_box(file_size)).unwrap();
        })
    });
}

criterion_group!(benches, bench_parse_range, bench_resolve_range);
criterion_main!(benches);
