juniper/benches/bench.rs

137 lines
2.5 KiB
Rust
Raw Normal View History

2020-03-20 11:11:06 -05:00
#[macro_use]
extern crate bencher;
2019-11-06 02:37:35 -06:00
extern crate juniper;
use bencher::Bencher;
use juniper::{execute_sync, RootNode, EmptyMutation, EmptySubscription, Variables};
use juniper::tests::fixtures::starwars::model::Database;
2019-11-06 02:37:35 -06:00
fn query_type_name(b: &mut Bencher) {
let database = Database::new();
let schema = RootNode::new(
&database,
EmptyMutation::<Database>::new(),
EmptySubscription::<Database>::new()
);
2019-11-06 02:37:35 -06:00
let doc = r#"
query IntrospectionQueryTypeQuery {
__schema {
queryType {
name
}
}
}"#;
b.iter(|| execute_sync(doc, None, &schema, &Variables::new(), &database));
2019-11-06 02:37:35 -06:00
}
fn introspection_query(b: &mut Bencher) {
let database = Database::new();
let schema = RootNode::new(
&database,
EmptyMutation::<Database>::new(),
EmptySubscription::<Database>::new(),
);
2019-11-06 02:37:35 -06:00
let doc = r#"
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
}
}
}
}
}
}
}
}
"#;
b.iter(|| execute_sync(doc, None, &schema, &Variables::new(), &database));
2019-11-06 02:37:35 -06:00
}
benchmark_group!(queries, query_type_name, introspection_query);
benchmark_main!(queries);