| 1 |
use winnow::combinator::repeat; |
| 2 |
use winnow::prelude::*; |
| 3 |
use winnow::Result; |
| 4 |
|
| 5 |
mod parser; |
| 6 |
mod parser_str; |
| 7 |
|
| 8 |
fn bench_ini(c: &mut criterion::Criterion) { |
| 9 |
let str = "[owner] |
| 10 |
name=John Doe |
| 11 |
organization=Acme Widgets Inc. |
| 12 |
|
| 13 |
[database] |
| 14 |
server=192.0.2.62 |
| 15 |
port=143 |
| 16 |
file=payroll.dat |
| 17 |
\0"; |
| 18 |
|
| 19 |
let mut group = c.benchmark_group("ini"); |
| 20 |
group.throughput(criterion::Throughput::Bytes(str.len() as u64)); |
| 21 |
group.bench_function(criterion::BenchmarkId::new("bytes", str.len()), |b| { |
| 22 |
b.iter(|| parser::categories.parse_peek(str.as_bytes()).unwrap()); |
| 23 |
}); |
| 24 |
group.bench_function(criterion::BenchmarkId::new("str", str.len()), |b| { |
| 25 |
b.iter(|| parser_str::categories.parse_peek(str).unwrap()); |
| 26 |
}); |
| 27 |
} |
| 28 |
|
| 29 |
fn bench_ini_keys_and_values(c: &mut criterion::Criterion) { |
| 30 |
let str = "server=192.0.2.62 |
| 31 |
port=143 |
| 32 |
file=payroll.dat |
| 33 |
\0"; |
| 34 |
|
| 35 |
fn acc<'s>(i: &mut parser::Stream<'s>) -> Result<Vec<(&'s str, &'s str)>> { |
| 36 |
repeat(0.., parser::key_value).parse_next(i) |
| 37 |
} |
| 38 |
|
| 39 |
let mut group = c.benchmark_group("ini keys and values"); |
| 40 |
group.throughput(criterion::Throughput::Bytes(str.len() as u64)); |
| 41 |
group.bench_function(criterion::BenchmarkId::new("bytes", str.len()), |b| { |
| 42 |
b.iter(|| acc.parse_peek(str.as_bytes()).unwrap()); |
| 43 |
}); |
| 44 |
} |
| 45 |
|
| 46 |
fn bench_ini_key_value(c: &mut criterion::Criterion) { |
| 47 |
let str = "server=192.0.2.62\n"; |
| 48 |
|
| 49 |
let mut group = c.benchmark_group("ini key value"); |
| 50 |
group.throughput(criterion::Throughput::Bytes(str.len() as u64)); |
| 51 |
group.bench_function(criterion::BenchmarkId::new("bytes", str.len()), |b| { |
| 52 |
b.iter(|| parser::key_value.parse_peek(str.as_bytes()).unwrap()); |
| 53 |
}); |
| 54 |
} |
| 55 |
|
| 56 |
criterion::criterion_group!( |
| 57 |
benches, |
| 58 |
bench_ini, |
| 59 |
bench_ini_keys_and_values, |
| 60 |
bench_ini_key_value |
| 61 |
); |
| 62 |
criterion::criterion_main!(benches); |