Sha256: f4b54895ed523c462ce327a5205b0b99591eb7056fe9de9abe3f809eff287386

Contents?: true

Size: 1.78 KB

Versions: 13

Compression:

Stored size: 1.78 KB

Contents

#[macro_use]
extern crate criterion;

use criterion::Criterion;

use winnow::ascii::float;
use winnow::binary::be_u64;
use winnow::error::ErrMode;
use winnow::error::ErrorKind;
use winnow::error::InputError;
use winnow::error::ParserError;
use winnow::prelude::*;
use winnow::stream::ParseSlice;

type Stream<'i> = &'i [u8];

fn parser(i: &mut Stream<'_>) -> PResult<u64> {
    be_u64.parse_next(i)
}

fn number(c: &mut Criterion) {
    let data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];

    parser
        .parse_peek(&data[..])
        .expect("should parse correctly");
    c.bench_function("number", move |b| {
        b.iter(|| parser.parse_peek(&data[..]).unwrap());
    });
}

fn float_bytes(c: &mut Criterion) {
    println!(
        "float_bytes result: {:?}",
        float::<_, f64, InputError<_>>.parse_peek(&b"-1.234E-12"[..])
    );
    c.bench_function("float bytes", |b| {
        b.iter(|| float::<_, f64, InputError<_>>.parse_peek(&b"-1.234E-12"[..]));
    });
}

fn float_str(c: &mut Criterion) {
    println!(
        "float_str result: {:?}",
        float::<_, f64, InputError<_>>.parse_peek("-1.234E-12")
    );
    c.bench_function("float str", |b| {
        b.iter(|| float::<_, f64, InputError<_>>.parse_peek("-1.234E-12"));
    });
}

fn std_float(input: &mut &[u8]) -> PResult<f64> {
    match input.parse_slice() {
        Some(n) => Ok(n),
        None => Err(ErrMode::from_error_kind(input, ErrorKind::Slice)),
    }
}

fn std_float_bytes(c: &mut Criterion) {
    println!(
        "std_float_bytes result: {:?}",
        std_float.parse_peek(&b"-1.234E-12"[..])
    );
    c.bench_function("std_float bytes", |b| {
        b.iter(|| std_float.parse_peek(&b"-1.234E-12"[..]));
    });
}

criterion_group!(benches, number, float_bytes, std_float_bytes, float_str);
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/number.rs
wasmtime-28.0.0 ./ext/cargo-vendor/winnow-0.6.22/benches/number.rs
wasmtime-27.0.0 ./ext/cargo-vendor/winnow-0.6.20/benches/number.rs
wasmtime-26.0.0 ./ext/cargo-vendor/winnow-0.6.20/benches/number.rs
wasmtime-25.0.2 ./ext/cargo-vendor/winnow-0.6.18/benches/number.rs
wasmtime-25.0.1 ./ext/cargo-vendor/winnow-0.6.18/benches/number.rs
wasmtime-25.0.0 ./ext/cargo-vendor/winnow-0.6.18/benches/number.rs
wasmtime-24.0.0 ./ext/cargo-vendor/winnow-0.6.18/benches/number.rs
wasmtime-23.0.2 ./ext/cargo-vendor/winnow-0.6.7/benches/number.rs
wasmtime-22.0.0 ./ext/cargo-vendor/winnow-0.6.7/benches/number.rs
wasmtime-21.0.1 ./ext/cargo-vendor/winnow-0.6.7/benches/number.rs
wasmtime-20.0.2 ./ext/cargo-vendor/winnow-0.6.7/benches/number.rs
wasmtime-20.0.0 ./ext/cargo-vendor/winnow-0.6.7/benches/number.rs