Upgrade criterion
crate 0.4 version (#1103)
- fix `juniper_benchmarks` sub-crate compilation - add CI job to track `juniper_benchmarks` sub-crate regressions Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Kai Ren <tyranron@gmail.com>
This commit is contained in:
parent
4b89d61f21
commit
2b1a2a7f5d
3 changed files with 81 additions and 69 deletions
15
.github/workflows/ci.yml
vendored
15
.github/workflows/ci.yml
vendored
|
@ -23,6 +23,7 @@ jobs:
|
||||||
pr:
|
pr:
|
||||||
if: ${{ github.event_name == 'pull_request' }}
|
if: ${{ github.event_name == 'pull_request' }}
|
||||||
needs:
|
needs:
|
||||||
|
- bench
|
||||||
- clippy
|
- clippy
|
||||||
- example
|
- example
|
||||||
- feature
|
- feature
|
||||||
|
@ -73,6 +74,19 @@ jobs:
|
||||||
# Testing #
|
# Testing #
|
||||||
###########
|
###########
|
||||||
|
|
||||||
|
bench:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
profile: minimal
|
||||||
|
toolchain: stable
|
||||||
|
override: true
|
||||||
|
|
||||||
|
- run: cargo clippy -p juniper_benchmarks --benches -- -D warnings
|
||||||
|
- run: cargo bench -p juniper_benchmarks
|
||||||
|
|
||||||
example:
|
example:
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
|
@ -295,6 +309,7 @@ jobs:
|
||||||
release-github:
|
release-github:
|
||||||
name: Release on GitHub
|
name: Release on GitHub
|
||||||
needs:
|
needs:
|
||||||
|
- bench
|
||||||
- clippy
|
- clippy
|
||||||
- example
|
- example
|
||||||
- feature
|
- feature
|
||||||
|
|
|
@ -10,7 +10,7 @@ futures = "0.3"
|
||||||
juniper = { path = "../juniper" }
|
juniper = { path = "../juniper" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
criterion = "0.3"
|
criterion = "0.4"
|
||||||
tokio = { version = "1.0", features = ["rt-multi-thread"] }
|
tokio = { version = "1.0", features = ["rt-multi-thread"] }
|
||||||
|
|
||||||
[[bench]]
|
[[bench]]
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
use criterion::{criterion_group, criterion_main, Criterion, ParameterizedBenchmark};
|
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
|
||||||
|
|
||||||
use juniper::InputValue;
|
use juniper::InputValue;
|
||||||
use juniper_benchmarks as j;
|
use juniper_benchmarks as j;
|
||||||
|
|
||||||
fn bench_sync_vs_async_users_flat_instant(c: &mut Criterion) {
|
fn bench_sync_vs_async_users_flat_instant(c: &mut Criterion) {
|
||||||
const ASYNC_QUERY: &'static str = r#"
|
// language=GraphQL
|
||||||
|
const ASYNC_QUERY: &str = r#"
|
||||||
query Query($id: Int) {
|
query Query($id: Int) {
|
||||||
users_async_instant(ids: [$id]!) {
|
users_async_instant(ids: [$id]!) {
|
||||||
id
|
id
|
||||||
|
@ -15,7 +16,8 @@ fn bench_sync_vs_async_users_flat_instant(c: &mut Criterion) {
|
||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
const SYNC_QUERY: &'static str = r#"
|
// language=GraphQL
|
||||||
|
const SYNC_QUERY: &str = r#"
|
||||||
query Query($id: Int) {
|
query Query($id: Int) {
|
||||||
users_sync_instant(ids: [$id]!) {
|
users_sync_instant(ids: [$id]!) {
|
||||||
id
|
id
|
||||||
|
@ -26,12 +28,10 @@ fn bench_sync_vs_async_users_flat_instant(c: &mut Criterion) {
|
||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
c.bench(
|
let mut group = c.benchmark_group("Sync vs Async - Users Flat - Instant");
|
||||||
"Sync vs Async - Users Flat - Instant",
|
for count in [1, 10] {
|
||||||
ParameterizedBenchmark::new(
|
group.bench_function(BenchmarkId::new("Sync", count), |b| {
|
||||||
"Sync",
|
let ids = (0..count)
|
||||||
|b, count| {
|
|
||||||
let ids = (0..*count)
|
|
||||||
.map(|x| InputValue::scalar(x as i32))
|
.map(|x| InputValue::scalar(x as i32))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
let ids = InputValue::list(ids);
|
let ids = InputValue::list(ids);
|
||||||
|
@ -41,16 +41,14 @@ fn bench_sync_vs_async_users_flat_instant(c: &mut Criterion) {
|
||||||
vec![("ids".to_owned(), ids.clone())].into_iter().collect(),
|
vec![("ids".to_owned(), ids.clone())].into_iter().collect(),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
},
|
});
|
||||||
vec![1, 10],
|
|
||||||
)
|
group.bench_function(BenchmarkId::new("Async - Single Thread", count), |b| {
|
||||||
.with_function("Async - Single Thread", |b, count| {
|
let rt = tokio::runtime::Builder::new_current_thread()
|
||||||
let mut rt = tokio::runtime::Builder::new()
|
|
||||||
.basic_scheduler()
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let ids = (0..*count)
|
let ids = (0..count)
|
||||||
.map(|x| InputValue::scalar(x as i32))
|
.map(|x| InputValue::scalar(x as i32))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
let ids = InputValue::list(ids);
|
let ids = InputValue::list(ids);
|
||||||
|
@ -62,14 +60,12 @@ fn bench_sync_vs_async_users_flat_instant(c: &mut Criterion) {
|
||||||
);
|
);
|
||||||
rt.block_on(f)
|
rt.block_on(f)
|
||||||
})
|
})
|
||||||
})
|
});
|
||||||
.with_function("Async - Threadpool", |b, count| {
|
|
||||||
let mut rt = tokio::runtime::Builder::new()
|
|
||||||
.threaded_scheduler()
|
|
||||||
.build()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let ids = (0..*count)
|
group.bench_function(BenchmarkId::new("Async - Threadpool", count), |b| {
|
||||||
|
let rt = tokio::runtime::Builder::new_multi_thread().build().unwrap();
|
||||||
|
|
||||||
|
let ids = (0..count)
|
||||||
.map(|x| InputValue::scalar(x as i32))
|
.map(|x| InputValue::scalar(x as i32))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
let ids = InputValue::list(ids);
|
let ids = InputValue::list(ids);
|
||||||
|
@ -81,8 +77,9 @@ fn bench_sync_vs_async_users_flat_instant(c: &mut Criterion) {
|
||||||
);
|
);
|
||||||
rt.block_on(f)
|
rt.block_on(f)
|
||||||
})
|
})
|
||||||
}),
|
});
|
||||||
);
|
}
|
||||||
|
group.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
criterion_group!(benches, bench_sync_vs_async_users_flat_instant);
|
criterion_group!(benches, bench_sync_vs_async_users_flat_instant);
|
||||||
|
|
Loading…
Reference in a new issue