-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add combine based benchmark to catch exponential regression
- Loading branch information
Markus Westerlind
committed
Feb 4, 2020
1 parent
48d49d2
commit 74ac6e8
Showing
4 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "combine" | ||
version = "0.1.0" | ||
authors = ["Markus Westerlind <[email protected]>"] | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
|
||
[workspace] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use std::marker::PhantomData; | ||
|
||
pub trait Parser<Input> { | ||
type Output; | ||
|
||
fn or<P2>(self, p: P2) -> Or<Self, P2> | ||
where | ||
Self: Sized, | ||
P2: Parser<Input, Output = Self::Output>, | ||
{ | ||
Or(self, p) | ||
} | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! choice { | ||
($first : expr) => { | ||
$first | ||
}; | ||
($first : expr, $($rest : expr),+) => { | ||
$first.or(choice!($($rest),+)) | ||
} | ||
} | ||
|
||
pub struct Or<P1, P2>(P1, P2); | ||
impl<Input, P1, P2> Parser<Input> for Or<P1, P2> | ||
where | ||
P1: Parser<Input, Output = P2::Output>, | ||
P2: Parser<Input>, | ||
{ | ||
type Output = P2::Output; | ||
} | ||
|
||
pub struct P<I, O>(PhantomData<fn(I) -> O>); | ||
impl<Input, O> Parser<Input> for P<Input, O> { | ||
type Output = O; | ||
} | ||
|
||
pub fn token<I>(_: u8) -> impl Parser<I, Output = u8> { | ||
P(PhantomData) | ||
} | ||
|
||
fn mcc_payload_item<I>() -> impl Parser<I, Output = u8> { | ||
choice!( | ||
token(b'G'), | ||
token(b'G'), | ||
token(b'G'), | ||
token(b'G'), | ||
token(b'G'), | ||
token(b'G'), | ||
token(b'G'), | ||
token(b'G'), | ||
token(b'G'), | ||
token(b'G'), | ||
token(b'G'), | ||
token(b'G'), | ||
token(b'G'), | ||
token(b'G') | ||
) | ||
} | ||
|
||
fn main() {} |