#![allow(missing_docs)]

use std::hint::black_box;

use criterion::{Criterion, criterion_group, criterion_main};

const SUBIT_DOC: &str = include_str!("subit_en.txt");

fn benchmark(c: &mut Criterion) {
    let escaped = SUBIT_DOC.escape_default().to_string();

    let mut g = c.benchmark_group("zero unicode unescape");

    g.bench_function("fast-unescape-try-into", |b| {
        b.iter(|| {
            let mut buf = String::new();
            let _ = fast_unescape::try_unescape_into(black_box(&escaped), black_box(&mut buf));
        })
    });
    g.bench_function("fast-unescape-into", |b| {
        b.iter(|| {
            let mut buf = String::new();
            fast_unescape::unescape_into(black_box(&escaped), black_box(&mut buf));
        })
    });

    g.bench_function("fast-unescape-cow", |b| {
        b.iter(|| {
            let s = fast_unescape::unescape(black_box(&escaped));
            drop(black_box(s));
        })
    });
    g.bench_function("fast-unescape-try-cow", |b| {
        b.iter(|| {
            let s = fast_unescape::try_unescape(black_box(&escaped));
            drop(black_box(s));
        })
    });

    // alternatives
    g.bench_function("unescaper", |b| {
        b.iter(|| {
            let s = unescaper::unescape(black_box(&escaped)).unwrap();
            drop(black_box(s));
        })
    });

    g.finish();
}

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