-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: test & benchmark parsing introspection (#1098)
- Loading branch information
Showing
4 changed files
with
285 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,72 @@ | ||
use divan::AllocProfiler; | ||
|
||
#[global_allocator] | ||
static ALLOC: AllocProfiler = AllocProfiler::system(); | ||
// use divan::AllocProfiler; | ||
// #[global_allocator] | ||
// static ALLOC: AllocProfiler = AllocProfiler::system(); | ||
|
||
fn main() { | ||
// Run registered benchmarks. | ||
divan::main(); | ||
} | ||
|
||
const QUERY: &str = include_str!("../tests/executables/kitchen-sink.graphql"); | ||
mod kitchen_sink { | ||
const QUERY: &str = include_str!("../tests/executables/kitchen-sink.graphql"); | ||
|
||
#[divan::bench] | ||
fn cynic_parser() -> cynic_parser::ExecutableDocument { | ||
cynic_parser::parse_executable_document(QUERY).unwrap() | ||
} | ||
#[divan::bench] | ||
fn cynic_parser() -> cynic_parser::ExecutableDocument { | ||
cynic_parser::parse_executable_document(QUERY).unwrap() | ||
} | ||
|
||
#[divan::bench( | ||
types = [ | ||
&str, | ||
String | ||
] | ||
)] | ||
fn graphql_parser<T>() -> graphql_parser::query::Document<'static, T> | ||
where | ||
T: graphql_parser::query::Text<'static>, | ||
{ | ||
graphql_parser::parse_query(QUERY).unwrap() | ||
} | ||
#[divan::bench( | ||
types = [ | ||
&str, | ||
String | ||
] | ||
)] | ||
fn graphql_parser<T>() -> graphql_parser::query::Document<'static, T> | ||
where | ||
T: graphql_parser::query::Text<'static>, | ||
{ | ||
graphql_parser::parse_query(QUERY).unwrap() | ||
} | ||
|
||
#[divan::bench] | ||
fn async_graphql_parser() -> async_graphql_parser::types::ExecutableDocument { | ||
async_graphql_parser::parse_query(QUERY).unwrap() | ||
} | ||
|
||
#[divan::bench] | ||
fn async_graphql_parser() -> async_graphql_parser::types::ExecutableDocument { | ||
async_graphql_parser::parse_query(QUERY).unwrap() | ||
#[divan::bench] | ||
fn apollo_parser() -> apollo_parser::SyntaxTree { | ||
apollo_parser::Parser::new(QUERY).parse() | ||
} | ||
} | ||
|
||
#[divan::bench] | ||
fn apollo_parser() -> apollo_parser::SyntaxTree { | ||
apollo_parser::Parser::new(QUERY).parse() | ||
mod introspection { | ||
const QUERY: &str = include_str!("../tests/executables/introspection.graphql"); | ||
|
||
#[divan::bench] | ||
fn cynic_parser() -> cynic_parser::ExecutableDocument { | ||
cynic_parser::parse_executable_document(QUERY).unwrap() | ||
} | ||
|
||
#[divan::bench( | ||
types = [ | ||
&str, | ||
String | ||
] | ||
)] | ||
fn graphql_parser<T>() -> graphql_parser::query::Document<'static, T> | ||
where | ||
T: graphql_parser::query::Text<'static>, | ||
{ | ||
graphql_parser::parse_query(QUERY).unwrap() | ||
} | ||
|
||
#[divan::bench] | ||
fn async_graphql_parser() -> async_graphql_parser::types::ExecutableDocument { | ||
async_graphql_parser::parse_query(QUERY).unwrap() | ||
} | ||
|
||
#[divan::bench] | ||
fn apollo_parser() -> apollo_parser::SyntaxTree { | ||
apollo_parser::Parser::new(QUERY).parse() | ||
} | ||
} |
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,107 @@ | ||
query IntrospectionQuery { | ||
__schema { | ||
queryType { | ||
name | ||
} | ||
mutationType { | ||
name | ||
} | ||
subscriptionType { | ||
name | ||
} | ||
types { | ||
...FullType | ||
} | ||
directives { | ||
name | ||
description | ||
locations | ||
args { | ||
...InputValue | ||
} | ||
} | ||
} | ||
} | ||
|
||
fragment FullType on __Type { | ||
kind | ||
name | ||
description | ||
fields(includeDeprecated: true) { | ||
name | ||
description | ||
args { | ||
...InputValue | ||
} | ||
type { | ||
...TypeRef | ||
} | ||
isDeprecated | ||
deprecationReason | ||
} | ||
inputFields { | ||
...InputValue | ||
} | ||
interfaces { | ||
...TypeRef | ||
} | ||
enumValues(includeDeprecated: true) { | ||
name | ||
description | ||
isDeprecated | ||
deprecationReason | ||
} | ||
possibleTypes { | ||
...TypeRef | ||
} | ||
} | ||
|
||
fragment InputValue on __InputValue { | ||
name | ||
description | ||
type { | ||
...TypeRef | ||
} | ||
defaultValue | ||
} | ||
|
||
fragment TypeRef on __Type { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
cynic-parser/tests/snapshots/executables__introspection.snap
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,112 @@ | ||
--- | ||
source: cynic-parser/tests/executables.rs | ||
expression: output | ||
--- | ||
query IntrospectionQuery { | ||
__schema { | ||
queryType { | ||
name | ||
} | ||
mutationType { | ||
name | ||
} | ||
subscriptionType { | ||
name | ||
} | ||
types { | ||
... FullType | ||
} | ||
directives { | ||
name | ||
description | ||
locations | ||
args { | ||
... InputValue | ||
} | ||
} | ||
} | ||
} | ||
|
||
fragment FullType on __Type { | ||
kind | ||
name | ||
description | ||
fields(includeDeprecated: true) { | ||
name | ||
description | ||
args { | ||
... InputValue | ||
} | ||
type { | ||
... TypeRef | ||
} | ||
isDeprecated | ||
deprecationReason | ||
} | ||
inputFields { | ||
... InputValue | ||
} | ||
interfaces { | ||
... TypeRef | ||
} | ||
enumValues(includeDeprecated: true) { | ||
name | ||
description | ||
isDeprecated | ||
deprecationReason | ||
} | ||
possibleTypes { | ||
... TypeRef | ||
} | ||
} | ||
|
||
fragment InputValue on __InputValue { | ||
name | ||
description | ||
type { | ||
... TypeRef | ||
} | ||
defaultValue | ||
} | ||
|
||
fragment TypeRef on __Type { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|