From c8819b000272a91f948377bafb56e9527ecaf851 Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Sun, 5 May 2024 17:09:01 +0200 Subject: [PATCH] add a benchmark for JSON where errors are not generated --- benchmarks/benches/json.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/benchmarks/benches/json.rs b/benchmarks/benches/json.rs index 94b84d31..0c6babbd 100644 --- a/benchmarks/benches/json.rs +++ b/benchmarks/benches/json.rs @@ -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}; @@ -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::>() + .process::>(data) + .unwrap(); + + // println!("data:\n{:?}", json(data)); + c.bench_function("json", |b| { + b.iter(|| { + json::>() + .process::>(data) + .unwrap() + }); + }); +} + static CANADA: &str = include_str!("../canada.json"); fn canada_json(c: &mut Criterion) { // test once to make sure it parses correctly @@ -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,