diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:25:56 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:25:56 +0000 |
commit | 018c4950b9406055dec02ef0fb52f132e2bb1e2c (patch) | |
tree | a835ebdf2088ef88fa681f8fad45f09922c1ae9a /vendor/winnow/benches | |
parent | Adding debian version 1.75.0+dfsg1-5. (diff) | |
download | rustc-018c4950b9406055dec02ef0fb52f132e2bb1e2c.tar.xz rustc-018c4950b9406055dec02ef0fb52f132e2bb1e2c.zip |
Merging upstream version 1.76.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.rs | 32 | ||||
-rw-r--r-- | vendor/winnow/benches/find_slice.rs | 50 |
2 files changed, 76 insertions, 6 deletions
diff --git a/vendor/winnow/benches/contains_token.rs b/vendor/winnow/benches/contains_token.rs index 2980ce6c8..675b08e58 100644 --- a/vendor/winnow/benches/contains_token.rs +++ b/vendor/winnow/benches/contains_token.rs @@ -3,7 +3,7 @@ use criterion::black_box; use winnow::combinator::alt; use winnow::combinator::repeat; use winnow::prelude::*; -use winnow::token::take_till1; +use winnow::token::take_till; use winnow::token::take_while; fn contains_token(c: &mut criterion::Criterion) { @@ -52,17 +52,29 @@ fn contains_token(c: &mut criterion::Criterion) { 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) + repeat( + 0.., + alt((take_while(1.., contains), take_till(1.., contains))), + ) + .parse_next(input) } 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) + repeat( + 0.., + alt((take_while(1.., contains), take_till(1.., contains))), + ) + .parse_next(input) } 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) + repeat( + 0.., + alt((take_while(1.., contains), take_till(1.., contains))), + ) + .parse_next(input) } fn parser_closure_or(input: &mut &str) -> PResult<usize> { @@ -78,12 +90,20 @@ fn parser_closure_or(input: &mut &str) -> PResult<usize> { || c == '8' || c == '9' }; - repeat(0.., alt((take_while(1.., contains), take_till1(contains)))).parse_next(input) + repeat( + 0.., + alt((take_while(1.., contains), take_till(1.., contains))), + ) + .parse_next(input) } 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) + repeat( + 0.., + alt((take_while(1.., contains), take_till(1.., contains))), + ) + .parse_next(input) } const CONTIGUOUS: &str = "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"; diff --git a/vendor/winnow/benches/find_slice.rs b/vendor/winnow/benches/find_slice.rs new file mode 100644 index 000000000..226fcadbf --- /dev/null +++ b/vendor/winnow/benches/find_slice.rs @@ -0,0 +1,50 @@ +use criterion::black_box; + +use winnow::combinator::repeat; +use winnow::prelude::*; +use winnow::token::take_until0; + +fn find_slice(c: &mut criterion::Criterion) { + let empty = ""; + let start_byte = "\r".repeat(100); + let start_slice = "\r\n".repeat(100); + let small = format!("{:>10}\r\n", "").repeat(100); + let large = format!("{:>10000}\r\n", "").repeat(100); + + let data = [ + ("empty", (empty, empty)), + ("start", (&start_byte, &start_slice)), + ("medium", (&small, &small)), + ("large", (&large, &large)), + ]; + let mut group = c.benchmark_group("find_slice"); + for (name, samples) in data { + group.bench_with_input( + criterion::BenchmarkId::new("byte", name), + samples.0, + |b, sample| { + b.iter(|| black_box(parser_byte.parse_peek(black_box(sample)).unwrap())); + }, + ); + + group.bench_with_input( + criterion::BenchmarkId::new("slice", name), + samples.1, + |b, sample| { + b.iter(|| black_box(parser_slice.parse_peek(black_box(sample)).unwrap())); + }, + ); + } + group.finish(); +} + +fn parser_byte(input: &mut &str) -> PResult<usize> { + repeat(0.., (take_until0("\r"), "\r")).parse_next(input) +} + +fn parser_slice(input: &mut &str) -> PResult<usize> { + repeat(0.., (take_until0("\r\n"), "\r\n")).parse_next(input) +} + +criterion::criterion_group!(benches, find_slice); +criterion::criterion_main!(benches); |