Sha256: a162e4f91ce2ed19b5b53f79d77c92eb52278f0788da9af8fee3ee62cebfe0a9

Contents?: true

Size: 982 Bytes

Versions: 13

Compression:

Stored size: 982 Bytes

Contents

mod parser;
mod parser_ast;
mod parser_lexer;

use winnow::prelude::*;

#[allow(clippy::eq_op, clippy::erasing_op)]
fn arithmetic(c: &mut criterion::Criterion) {
    let data = "  2*2 / ( 5 - 1) + 3 / 4 * (2 - 7 + 567 *12 /2) + 3*(1+2*( 45 /2))";
    let expected = 2 * 2 / (5 - 1) + 3 * (1 + 2 * (45 / 2));

    assert_eq!(parser::expr.parse(data), Ok(expected));
    assert_eq!(
        parser_ast::expr.parse(data).map(|ast| ast.eval()),
        Ok(expected)
    );
    assert_eq!(
        parser_lexer::expr2.parse(data).map(|ast| ast.eval()),
        Ok(expected)
    );
    c.bench_function("direct", |b| {
        b.iter(|| parser::expr.parse(data).unwrap());
    });
    c.bench_function("ast", |b| {
        b.iter(|| parser_ast::expr.parse(data).unwrap().eval());
    });
    c.bench_function("lexer", |b| {
        b.iter(|| parser_lexer::expr2.parse_peek(data).unwrap());
    });
}

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