Skip to content

Commit 96c1ad0

Browse files
committed
Use bencher crate to run benchmarks on stable rust
1 parent 7a0439b commit 96c1ad0

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ repository = "https://github.com/mhallin/juniper"
99
readme = "README.md"
1010
keywords = ["graphql", "server", "iron", "http", "web"]
1111

12+
[[bench]]
13+
name = "bench"
14+
harness = false
15+
path = "benches/bench.rs"
16+
1217
[features]
1318
default = []
1419
nightly = []
@@ -25,3 +30,4 @@ router = "^0.2.0"
2530
mount = "^0.2.1"
2631
logger = "^0.1.0"
2732
iron-test = "^0.4.0"
33+
bencher = "^0.1.2"

src/tests/bench.rs renamed to benches/bench.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
use test::Bencher;
1+
#[macro_use] extern crate bencher;
2+
extern crate juniper;
3+
4+
use bencher::Bencher;
25

36
use std::collections::{HashMap};
47

5-
use schema::model::RootNode;
6-
use tests::model::Database;
8+
use juniper::{execute, RootNode, EmptyMutation};
9+
use juniper::tests::model::Database;
710

8-
#[bench]
911
fn query_type_name(b: &mut Bencher) {
1012
let database = Database::new();
11-
let schema = RootNode::new(&database, ());
13+
let schema = RootNode::new(&database, EmptyMutation::<Database>::new());
1214

1315
let doc = r#"
1416
query IntrospectionQueryTypeQuery {
@@ -19,13 +21,12 @@ fn query_type_name(b: &mut Bencher) {
1921
}
2022
}"#;
2123

22-
b.iter(|| ::execute(doc, None, &schema, &HashMap::new(), &database));
24+
b.iter(|| execute(doc, None, &schema, &HashMap::new(), &database));
2325
}
2426

25-
#[bench]
2627
fn introspection_query(b: &mut Bencher) {
2728
let database = Database::new();
28-
let schema = RootNode::new(&database, ());
29+
let schema = RootNode::new(&database, EmptyMutation::<Database>::new());
2930

3031
let doc = r#"
3132
query IntrospectionQuery {
@@ -121,5 +122,8 @@ fn introspection_query(b: &mut Bencher) {
121122
}
122123
"#;
123124

124-
b.iter(|| ::execute(doc, None, &schema, &HashMap::new(), &database));
125+
b.iter(|| execute(doc, None, &schema, &HashMap::new(), &database));
125126
}
127+
128+
benchmark_group!(queries, query_type_name, introspection_query);
129+
benchmark_main!(queries);

src/tests/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,3 @@ pub mod model;
22
mod schema;
33
pub mod query_tests;
44
pub mod introspection_tests;
5-
6-
#[cfg(feature="nightly")]
7-
pub mod bench;

0 commit comments

Comments
 (0)