Sha256: 01061b696d94952e0f9cf2e7bb4bb2cae6cf1069e36d9fadfed4379e8502762f

Contents?: true

Size: 1.92 KB

Versions: 4

Compression:

Stored size: 1.92 KB

Contents

use winnow::prelude::*;
use winnow::Partial;

mod json;
mod parser;
mod parser_dispatch;
mod parser_partial;

fn json_bench(c: &mut criterion::Criterion) {
    let data = [("small", SMALL), ("canada", CANADA)];
    let mut group = c.benchmark_group("json");
    for (name, sample) in data {
        let len = sample.len();
        group.throughput(criterion::Throughput::Bytes(len as u64));

        group.bench_with_input(criterion::BenchmarkId::new("unit", name), &len, |b, _| {
            type Error<'i> = ();

            b.iter(|| parser::json::<Error<'_>>.parse_peek(sample).unwrap());
        });
        group.bench_with_input(
            criterion::BenchmarkId::new("context", name),
            &len,
            |b, _| {
                type Error = winnow::error::ContextError;

                b.iter(|| parser::json::<Error>.parse_peek(sample).unwrap());
            },
        );
        group.bench_with_input(
            criterion::BenchmarkId::new("dispatch", name),
            &len,
            |b, _| {
                type Error = winnow::error::ContextError;

                b.iter(|| parser_dispatch::json::<Error>.parse_peek(sample).unwrap());
            },
        );
        group.bench_with_input(
            criterion::BenchmarkId::new("streaming", name),
            &len,
            |b, _| {
                type Error = winnow::error::ContextError;

                b.iter(|| {
                    parser_partial::json::<Error>
                        .parse_peek(Partial::new(sample))
                        .unwrap()
                });
            },
        );
    }
    group.finish();
}

const SMALL: &str = "  { \"a\"\t: 42,
  \"b\": [ \"x\", \"y\", 12 ,\"\\u2014\", \"\\uD83D\\uDE10\"] ,
  \"c\": { \"hello\" : \"world\"
  }
  }  ";

const CANADA: &str = include_str!("../../third_party/nativejson-benchmark/data/canada.json");

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/winnow-0.6.24/examples/json/bench.rs
wasmtime-28.0.0 ./ext/cargo-vendor/winnow-0.6.22/examples/json/bench.rs
wasmtime-27.0.0 ./ext/cargo-vendor/winnow-0.6.20/examples/json/bench.rs
wasmtime-26.0.0 ./ext/cargo-vendor/winnow-0.6.20/examples/json/bench.rs