]>
git.proxmox.com Git - rustc.git/blob - vendor/winnow-0.4.7/examples/json/bench.rs
8 fn json_bench(c
: &mut criterion
::Criterion
) {
9 let data
= [("small", SMALL
), ("canada", CANADA
)];
10 let mut group
= c
.benchmark_group("json");
11 for (name
, sample
) in data
{
12 let len
= sample
.len();
13 group
.throughput(criterion
::Throughput
::Bytes(len
as u64));
15 group
.bench_with_input(criterion
::BenchmarkId
::new("basic", name
), &len
, |b
, _
| {
16 type Error
<'i
> = winnow
::error
::Error
<parser
::Stream
<'i
>>;
18 b
.iter(|| parser
::json
::<Error
>(sample
).unwrap());
20 group
.bench_with_input(
21 criterion
::BenchmarkId
::new("verbose", name
),
24 type Error
<'i
> = winnow
::error
::VerboseError
<parser
::Stream
<'i
>>;
26 b
.iter(|| parser
::json
::<Error
>(sample
).unwrap());
29 group
.bench_with_input(
30 criterion
::BenchmarkId
::new("dispatch", name
),
33 type Error
<'i
> = winnow
::error
::Error
<parser
::Stream
<'i
>>;
35 b
.iter(|| parser_dispatch
::json
::<Error
>(sample
).unwrap());
38 group
.bench_with_input(
39 criterion
::BenchmarkId
::new("streaming", name
),
42 type Error
<'i
> = winnow
::error
::Error
<parser_partial
::Stream
<'i
>>;
44 b
.iter(|| parser_partial
::json
::<Error
>(Partial
::new(sample
)).unwrap());
51 const SMALL
: &str = " { \"a\"\t: 42,
52 \"b\": [ \"x\", \"y\", 12 ,\"\\u2014\", \"\\uD83D\\uDE10\"] ,
53 \"c\": { \"hello\" : \"world\"
57 const CANADA
: &str = include_str
!("../../third_party/nativejson-benchmark/data/canada.json");
59 criterion
::criterion_group
!(benches
, json_bench
,);
60 criterion
::criterion_main
!(benches
);