Moved benchmark from side repo
This commit is contained in:
parent
b38130575c
commit
2922c1bb4b
|
@ -3,3 +3,5 @@ Cargo.lock
|
|||
.idea
|
||||
.DS_Store
|
||||
node_modules
|
||||
|
||||
benchmark/target
|
||||
|
|
|
@ -64,4 +64,5 @@ members = [
|
|||
"async-graphql-warp",
|
||||
"async-graphql-tide",
|
||||
# "async-graphql-lambda",
|
||||
]
|
||||
"benchmark",
|
||||
]
|
||||
|
|
|
@ -54,11 +54,15 @@ To see how you would create a Relay-compliant server using async-graphql, warp,
|
|||
|
||||
## Benchmark
|
||||
|
||||
Ensure that there is no CPU-heavy process in background!
|
||||
|
||||
```shell script
|
||||
git clone https://github.com/async-graphql/benchmark
|
||||
cargo run --release
|
||||
cd benchmark
|
||||
cargo bench
|
||||
```
|
||||
|
||||
Now HTML report is available at `benchmark/target/criterion/report`
|
||||
|
||||
## Features
|
||||
|
||||
* Fully support async/await
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
[package]
|
||||
name = "graphql-benchmark"
|
||||
version = "0.1.0"
|
||||
authors = ["sunli <scott_s829@163.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = "0.3"
|
||||
simple = { path = "simple" }
|
||||
|
||||
[[bench]]
|
||||
name = "simple"
|
||||
harness = false
|
|
@ -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);
|
|
@ -0,0 +1,13 @@
|
|||
[package]
|
||||
name = "simple"
|
||||
version = "0.1.0"
|
||||
authors = ["Ivan Plesskih <terma95@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
async-graphql = { path = "../.." }
|
||||
async-std = { version = "1.5.0", features = ["attributes"] }
|
||||
futures = "0.3.4"
|
||||
serde_json = "*"
|
||||
lazy_static = "*"
|
||||
async-graphql-parser = { path = "../../async-graphql-parser" }
|
|
@ -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()
|
||||
}
|
Loading…
Reference in New Issue