Sha256: 4853142ad538403b17c5f2d486b958a11628039b5366925927e61743ea462c48

Contents?: true

Size: 1.48 KB

Versions: 13

Compression:

Stored size: 1.48 KB

Contents

use criterion::black_box;

use winnow::combinator::repeat;
use winnow::prelude::*;
use winnow::token::take_until;

fn find_slice(c: &mut criterion::Criterion) {
    let empty = "";
    let start_byte = "\r".repeat(100);
    let start_slice = "\r\n".repeat(100);
    let small = format!("{:>10}\r\n", "").repeat(100);
    let large = format!("{:>10000}\r\n", "").repeat(100);

    let data = [
        ("empty", (empty, empty)),
        ("start", (&start_byte, &start_slice)),
        ("medium", (&small, &small)),
        ("large", (&large, &large)),
    ];
    let mut group = c.benchmark_group("find_slice");
    for (name, samples) in data {
        group.bench_with_input(
            criterion::BenchmarkId::new("byte", name),
            samples.0,
            |b, sample| {
                b.iter(|| black_box(parser_byte.parse_peek(black_box(sample)).unwrap()));
            },
        );

        group.bench_with_input(
            criterion::BenchmarkId::new("slice", name),
            samples.1,
            |b, sample| {
                b.iter(|| black_box(parser_slice.parse_peek(black_box(sample)).unwrap()));
            },
        );
    }
    group.finish();
}

fn parser_byte(input: &mut &str) -> PResult<usize> {
    repeat(0.., (take_until(0.., "\r"), "\r")).parse_next(input)
}

fn parser_slice(input: &mut &str) -> PResult<usize> {
    repeat(0.., (take_until(0.., "\r\n"), "\r\n")).parse_next(input)
}

criterion::criterion_group!(benches, find_slice);
criterion::criterion_main!(benches);

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/winnow-0.6.24/benches/find_slice.rs
wasmtime-28.0.0 ./ext/cargo-vendor/winnow-0.6.22/benches/find_slice.rs
wasmtime-27.0.0 ./ext/cargo-vendor/winnow-0.6.20/benches/find_slice.rs
wasmtime-26.0.0 ./ext/cargo-vendor/winnow-0.6.20/benches/find_slice.rs
wasmtime-25.0.2 ./ext/cargo-vendor/winnow-0.6.18/benches/find_slice.rs
wasmtime-25.0.1 ./ext/cargo-vendor/winnow-0.6.18/benches/find_slice.rs
wasmtime-25.0.0 ./ext/cargo-vendor/winnow-0.6.18/benches/find_slice.rs
wasmtime-24.0.0 ./ext/cargo-vendor/winnow-0.6.18/benches/find_slice.rs
wasmtime-23.0.2 ./ext/cargo-vendor/winnow-0.6.7/benches/find_slice.rs
wasmtime-22.0.0 ./ext/cargo-vendor/winnow-0.6.7/benches/find_slice.rs
wasmtime-21.0.1 ./ext/cargo-vendor/winnow-0.6.7/benches/find_slice.rs
wasmtime-20.0.2 ./ext/cargo-vendor/winnow-0.6.7/benches/find_slice.rs
wasmtime-20.0.0 ./ext/cargo-vendor/winnow-0.6.7/benches/find_slice.rs