Skip to content

Added criterion #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,151 changes: 880 additions & 271 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -4,8 +4,10 @@ version = "0.1.0"
authors = ["sunli <[email protected]>"]
edition = "2018"

[dependencies]
async-graphql = "1.4.4"
async-std = { version = "1.5.0", features = ["attributes"] }
juniper = { git = "https://github.com/graphql-rust/juniper"}
futures = "0.3.4"
[dev-dependencies]
criterion = "0.3"
simple = { path = "simple" }

[[bench]]
name = "simple"
harness = false
12 changes: 12 additions & 0 deletions benches/simple.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use criterion::{criterion_group, criterion_main, Criterion, black_box};
use simple::{Q, run, parse, serialize, GQLResponse};

pub fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("run", |b| b.iter(|| run(black_box(Q))));
c.bench_function("parse", |b| b.iter(|| parse(black_box(Q))));
let res = GQLResponse(run(Q));
c.bench_function("serialize", |b| b.iter(|| serialize(black_box(&res))));
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
1,461 changes: 1,461 additions & 0 deletions simple/Cargo.lock

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions simple/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "simple"
version = "0.1.0"
authors = ["Ivan Plesskih <terma95@gmail.com>"]
edition = "2018"

[dependencies]
async-graphql = "1.14.10"
async-std = { version = "1.5.0", features = ["attributes"] }
futures = "0.3.4"
serde_json = "*"
lazy_static = "*"
async-graphql-parser = "*"
100 changes: 100 additions & 0 deletions simple/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
use async_graphql::*;
pub use http::GQLResponse;
use async_graphql_parser::{parse_query, query::Document};
use async_std::task;

pub struct QueryRoot;

#[Object]
impl QueryRoot {
#[field]
async fn value_i32(&self) -> i32 {
999
}

#[field]
async fn obj(&self) -> MyObj {
MyObj
}
}

pub struct MyObj;

#[Object]
impl MyObj {
#[field]
async fn value_i32(&self) -> i32 {
999
}

#[field]
async fn value_list(&self) -> &[i32] {
&[1, 2, 3, 4, 5, 6, 7, 8, 9]
}

#[field]
async fn obj(&self) -> MyObj {
MyObj
}
}

pub const Q: &str = r#"{
valueI32 obj {
valueI32 valueList obj {
valueI32 valueList obj {
valueI32 valueList obj {
valueI32 valueList obj {
valueI32 valueList obj {
valueI32 valueList obj {
valueI32 valueList obj {
valueI32 valueList obj {
valueI32 valueList obj {
valueI32 valueList obj {
valueI32 valueList obj {
valueI32 valueList obj {
valueI32 valueList obj {
valueI32 valueList obj {
valueI32 valueList
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}"#;

lazy_static::lazy_static! {
static ref S: Schema<QueryRoot, EmptyMutation, EmptySubscription> = Schema::new(QueryRoot, EmptyMutation, EmptySubscription);
// static ref D: Document = parse_query(Q).unwrap();
}

pub fn run(q: &str) -> Result<QueryResponse> {
task::block_on(async {
S.execute(q).await
})
}

pub fn parse(q: &str) -> Document {
parse_query(q).unwrap()
}

// pub fn validate() {
// check_rules(&S.env.registry, &D, S.validation_mode).unwrap();
// }
//
// pub fn resolve() {
// do_resolve(...).unwrap();
// }

pub fn serialize(r: &GQLResponse) -> String {
serde_json::to_string(&r).unwrap()
}
45 changes: 0 additions & 45 deletions src/async_graphql_benchmark.rs

This file was deleted.

49 changes: 0 additions & 49 deletions src/juniper_benchmark.rs

This file was deleted.

8 changes: 0 additions & 8 deletions src/main.rs

This file was deleted.