Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a benchmark for JSON where errors are not generated #1751

Merged
merged 1 commit into from
May 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion benchmarks/benches/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use nom::{
number::double,
number::recognize_float,
sequence::{delimited, preceded, separated_pair},
Complete, Emit, IResult, Mode, OutputM, Parser,
Check, Complete, Emit, IResult, Mode, OutputM, Parser,
};

use std::{collections::HashMap, marker::PhantomData, num::ParseIntError};
Expand Down Expand Up @@ -271,6 +271,28 @@ fn json_bench(c: &mut Criterion) {
});
}

fn json_bench_error_check(c: &mut Criterion) {
let data = " { \"a\"\t: 42,
\"b\": [ \"x\", \"y\", 12 ,\"\\u2014\", \"\\uD83D\\uDE10\"] ,
\"c\": { \"hello\" : \"world\"
}
} ";

// test once to make sure it parses correctly
json::<Error<&str>>()
.process::<OutputM<Emit, Check, Complete>>(data)
.unwrap();

// println!("data:\n{:?}", json(data));
c.bench_function("json", |b| {
b.iter(|| {
json::<Error<&str>>()
.process::<OutputM<Emit, Check, Complete>>(data)
.unwrap()
});
});
}

static CANADA: &str = include_str!("../canada.json");
fn canada_json(c: &mut Criterion) {
// test once to make sure it parses correctly
Expand Down Expand Up @@ -399,6 +421,7 @@ fn std_float_bytes(c: &mut Criterion) {
criterion_group!(
benches,
json_bench,
json_bench_error_check,
verbose_json,
canada_json,
verbose_canada_json,
Expand Down
Loading