Skip to content

Commit

Permalink
Add combine-based benchmark that caused a large performance regression
Browse files Browse the repository at this point in the history
  • Loading branch information
sdroege committed Dec 22, 2019
1 parent 2bd73fa commit ef7b1b4
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 0 deletions.
3 changes: 3 additions & 0 deletions collector/benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ programs.
- **coercions**: Contains a static array with 65,536 string literals, which
caused [poor performance](https://github.com/rust-lang/rust/issues/32278) in
the past.
- **combine**: Contains a small `combine`-based parser that caused a [large
performance regression](https://github.com/rust-lang/rust/issues/67454) in
the past.
- **ctfe-stress-4**: A stress test for compile-time function evaluation.
- **deeply-nested**: A small program that caused [exponential
behavior](https://github.com/rust-lang/rust/issues/38528) in the past.
Expand Down
2 changes: 2 additions & 0 deletions collector/benchmarks/combine/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
**/*.rs.bk
62 changes: 62 additions & 0 deletions collector/benchmarks/combine/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions collector/benchmarks/combine/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "combine-bench"
license = "MIT"
version = "0.1.0"
authors = ["Sebastian Dröge <[email protected]>", "François Laignel <[email protected]>"]
edition = "2018"

[dependencies]
combine = "3.8"
35 changes: 35 additions & 0 deletions collector/benchmarks/combine/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use combine::byte::hex_digit;
use combine::{choice, token};
use combine::{ParseError, Parser, RangeStream};

pub fn parse<'a, I: 'a>() -> impl Parser<Input = I, Output = u8>
where
I: RangeStream<Item = u8, Range = &'a [u8]>,
I::Error: ParseError<I::Item, I::Range, I::Position>,
{
choice!(
token(b'A').map(|_| 1),
token(b'B').map(|_| 2),
token(b'C').map(|_| 3),
token(b'D').map(|_| 4),
token(b'E').map(|_| 5),
token(b'F').map(|_| 6),
token(b'G').map(|_| 7),
token(b'H').map(|_| 8),
token(b'I').map(|_| 9),
token(b'J').map(|_| 10),
token(b'K').map(|_| 11),
token(b'L').map(|_| 12),
token(b'M').map(|_| 13),
token(b'N').map(|_| 14),
token(b'O').map(|_| 15),
token(b'P').map(|_| 16),
token(b'Q').map(|_| 17),
token(b'R').map(|_| 18),
(hex_digit(), hex_digit()).map(|(u, l)| {
let val = (u << 4) | l;
val
})
)
.message("while parsing")
}

0 comments on commit ef7b1b4

Please sign in to comment.