-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(parser): Stream tokens from the lexer (#115)
Co-authored-by: Iryna Shestak <[email protected]> Co-authored-by: Renée Kooi <[email protected]>
- Loading branch information
1 parent
e72853c
commit 87522b7
Showing
10 changed files
with
233 additions
and
130 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
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,52 @@ | ||
use apollo_parser::{ast, Lexer}; | ||
use criterion::*; | ||
|
||
fn parse_schema(schema: &str) { | ||
let parser = apollo_parser::Parser::new(schema); | ||
let tree = parser.parse(); | ||
let errors = tree.errors().collect::<Vec<_>>(); | ||
|
||
if !errors.is_empty() { | ||
panic!("error parsing query: {:?}", errors); | ||
} | ||
|
||
let document = tree.document(); | ||
|
||
for definition in document.definitions() { | ||
if let ast::Definition::OperationDefinition(operation) = definition { | ||
let selection_set = operation | ||
.selection_set() | ||
.expect("the node SelectionSet is not optional in the spec; qed"); | ||
for selection in selection_set.selections() { | ||
if let ast::Selection::Field(field) = selection { | ||
let _selection_set = field.selection_set(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
fn bench_supergraph_parser(c: &mut Criterion) { | ||
let schema = include_str!("../test_data/parser/ok/0032_supergraph.graphql"); | ||
|
||
c.bench_function("supergraph_parser", move |b| { | ||
b.iter(|| parse_schema(schema)) | ||
}); | ||
} | ||
|
||
fn bench_supergraph_lexer(c: &mut Criterion) { | ||
let schema = include_str!("../test_data/parser/ok/0032_supergraph.graphql"); | ||
|
||
c.bench_function("supergraph_lexer", move |b| { | ||
b.iter(|| { | ||
let lexer = Lexer::new(schema); | ||
|
||
for token_res in lexer { | ||
let _ = token_res; | ||
} | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, bench_supergraph_lexer, bench_supergraph_parser); | ||
criterion_main!(benches); |
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
Oops, something went wrong.