summaryrefslogtreecommitdiffstats
path: root/vendor/winnow/benches
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
commitd1b2d29528b7794b41e66fc2136e395a02f8529b (patch)
treea4a17504b260206dec3cf55b2dca82929a348ac2 /vendor/winnow/benches
parentReleasing progress-linux version 1.72.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.tar.xz
rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.zip
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/winnow/benches')
-rw-r--r--vendor/winnow/benches/contains_token.rs28
-rw-r--r--vendor/winnow/benches/number.rs34
2 files changed, 27 insertions, 35 deletions
diff --git a/vendor/winnow/benches/contains_token.rs b/vendor/winnow/benches/contains_token.rs
index a35c1b2b1..2980ce6c8 100644
--- a/vendor/winnow/benches/contains_token.rs
+++ b/vendor/winnow/benches/contains_token.rs
@@ -17,23 +17,20 @@ fn contains_token(c: &mut criterion::Criterion) {
let len = sample.len();
group.throughput(criterion::Throughput::Bytes(len as u64));
- group.bench_with_input(criterion::BenchmarkId::new("str", name), &len, |b, _| {
- b.iter(|| black_box(parser_str.parse_next(black_box(sample)).unwrap()));
- });
group.bench_with_input(criterion::BenchmarkId::new("slice", name), &len, |b, _| {
- b.iter(|| black_box(parser_slice.parse_next(black_box(sample)).unwrap()));
+ b.iter(|| black_box(parser_slice.parse_peek(black_box(sample)).unwrap()));
});
group.bench_with_input(criterion::BenchmarkId::new("array", name), &len, |b, _| {
- b.iter(|| black_box(parser_array.parse_next(black_box(sample)).unwrap()));
+ b.iter(|| black_box(parser_array.parse_peek(black_box(sample)).unwrap()));
});
group.bench_with_input(criterion::BenchmarkId::new("tuple", name), &len, |b, _| {
- b.iter(|| black_box(parser_tuple.parse_next(black_box(sample)).unwrap()));
+ b.iter(|| black_box(parser_tuple.parse_peek(black_box(sample)).unwrap()));
});
group.bench_with_input(
criterion::BenchmarkId::new("closure-or", name),
&len,
|b, _| {
- b.iter(|| black_box(parser_closure_or.parse_next(black_box(sample)).unwrap()));
+ b.iter(|| black_box(parser_closure_or.parse_peek(black_box(sample)).unwrap()));
},
);
group.bench_with_input(
@@ -43,7 +40,7 @@ fn contains_token(c: &mut criterion::Criterion) {
b.iter(|| {
black_box(
parser_closure_matches
- .parse_next(black_box(sample))
+ .parse_peek(black_box(sample))
.unwrap(),
)
});
@@ -53,27 +50,22 @@ fn contains_token(c: &mut criterion::Criterion) {
group.finish();
}
-fn parser_str(input: &str) -> IResult<&str, usize> {
- let contains = "0123456789";
- repeat(0.., alt((take_while(1.., contains), take_till1(contains)))).parse_next(input)
-}
-
-fn parser_slice(input: &str) -> IResult<&str, usize> {
+fn parser_slice(input: &mut &str) -> PResult<usize> {
let contains = &['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'][..];
repeat(0.., alt((take_while(1.., contains), take_till1(contains)))).parse_next(input)
}
-fn parser_array(input: &str) -> IResult<&str, usize> {
+fn parser_array(input: &mut &str) -> PResult<usize> {
let contains = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
repeat(0.., alt((take_while(1.., contains), take_till1(contains)))).parse_next(input)
}
-fn parser_tuple(input: &str) -> IResult<&str, usize> {
+fn parser_tuple(input: &mut &str) -> PResult<usize> {
let contains = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
repeat(0.., alt((take_while(1.., contains), take_till1(contains)))).parse_next(input)
}
-fn parser_closure_or(input: &str) -> IResult<&str, usize> {
+fn parser_closure_or(input: &mut &str) -> PResult<usize> {
let contains = |c: char| {
c == '0'
|| c == '1'
@@ -89,7 +81,7 @@ fn parser_closure_or(input: &str) -> IResult<&str, usize> {
repeat(0.., alt((take_while(1.., contains), take_till1(contains)))).parse_next(input)
}
-fn parser_closure_matches(input: &str) -> IResult<&str, usize> {
+fn parser_closure_matches(input: &mut &str) -> PResult<usize> {
let contains = |c: char| matches!(c, '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9');
repeat(0.., alt((take_while(1.., contains), take_till1(contains)))).parse_next(input)
}
diff --git a/vendor/winnow/benches/number.rs b/vendor/winnow/benches/number.rs
index b6c6fac57..d35d65c2e 100644
--- a/vendor/winnow/benches/number.rs
+++ b/vendor/winnow/benches/number.rs
@@ -6,63 +6,63 @@ use criterion::Criterion;
use winnow::ascii::float;
use winnow::binary::be_u64;
use winnow::error::ErrMode;
-use winnow::error::Error;
use winnow::error::ErrorKind;
+use winnow::error::InputError;
+use winnow::error::ParserError;
use winnow::prelude::*;
use winnow::stream::ParseSlice;
type Stream<'i> = &'i [u8];
-fn parser(i: Stream<'_>) -> IResult<Stream<'_>, u64> {
- be_u64(i)
+fn parser(i: &mut Stream<'_>) -> PResult<u64> {
+ be_u64.parse_next(i)
}
fn number(c: &mut Criterion) {
let data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
- parser(&data[..]).expect("should parse correctly");
+ parser
+ .parse_peek(&data[..])
+ .expect("should parse correctly");
c.bench_function("number", move |b| {
- b.iter(|| parser(&data[..]).unwrap());
+ b.iter(|| parser.parse_peek(&data[..]).unwrap());
});
}
fn float_bytes(c: &mut Criterion) {
println!(
"float_bytes result: {:?}",
- float::<_, f64, Error<_>>(&b"-1.234E-12"[..])
+ float::<_, f64, InputError<_>>.parse_peek(&b"-1.234E-12"[..])
);
c.bench_function("float bytes", |b| {
- b.iter(|| float::<_, f64, Error<_>>(&b"-1.234E-12"[..]));
+ b.iter(|| float::<_, f64, InputError<_>>.parse_peek(&b"-1.234E-12"[..]));
});
}
fn float_str(c: &mut Criterion) {
println!(
"float_str result: {:?}",
- float::<_, f64, Error<_>>("-1.234E-12")
+ float::<_, f64, InputError<_>>.parse_peek("-1.234E-12")
);
c.bench_function("float str", |b| {
- b.iter(|| float::<_, f64, Error<_>>("-1.234E-12"));
+ b.iter(|| float::<_, f64, InputError<_>>.parse_peek("-1.234E-12"));
});
}
-fn std_float(input: &[u8]) -> IResult<&[u8], f64, Error<&[u8]>> {
+fn std_float(input: &mut &[u8]) -> PResult<f64> {
match input.parse_slice() {
- Some(n) => Ok((&[], n)),
- None => Err(ErrMode::Backtrack(Error {
- input,
- kind: ErrorKind::Slice,
- })),
+ Some(n) => Ok(n),
+ None => Err(ErrMode::from_error_kind(input, ErrorKind::Slice)),
}
}
fn std_float_bytes(c: &mut Criterion) {
println!(
"std_float_bytes result: {:?}",
- std_float(&b"-1.234E-12"[..])
+ std_float.parse_peek(&b"-1.234E-12"[..])
);
c.bench_function("std_float bytes", |b| {
- b.iter(|| std_float(&b"-1.234E-12"[..]));
+ b.iter(|| std_float.parse_peek(&b"-1.234E-12"[..]));
});
}