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:
dependabot[bot] 2022-09-12 16:54:17 +00:00 committed by GitHub
parent 4b89d61f21
commit 2b1a2a7f5d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 81 additions and 69 deletions

View file

@ -23,6 +23,7 @@ jobs:
pr:
if: ${{ github.event_name == 'pull_request' }}
needs:
- bench
- clippy
- example
- feature
@ -73,6 +74,19 @@ jobs:
# 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:
strategy:
fail-fast: false
@ -295,6 +309,7 @@ jobs:
release-github:
name: Release on GitHub
needs:
- bench
- clippy
- example
- feature

View file

@ -10,7 +10,7 @@ futures = "0.3"
juniper = { path = "../juniper" }
[dev-dependencies]
criterion = "0.3"
criterion = "0.4"
tokio = { version = "1.0", features = ["rt-multi-thread"] }
[[bench]]

View file

@ -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_benchmarks as j;
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) {
users_async_instant(ids: [$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) {
users_sync_instant(ids: [$id]!) {
id
@ -24,14 +26,12 @@ fn bench_sync_vs_async_users_flat_instant(c: &mut Criterion) {
email
}
}
"#;
"#;
c.bench(
"Sync vs Async - Users Flat - Instant",
ParameterizedBenchmark::new(
"Sync",
|b, count| {
let ids = (0..*count)
let mut group = c.benchmark_group("Sync vs Async - Users Flat - Instant");
for count in [1, 10] {
group.bench_function(BenchmarkId::new("Sync", count), |b| {
let ids = (0..count)
.map(|x| InputValue::scalar(x as i32))
.collect::<Vec<_>>();
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![1, 10],
)
.with_function("Async - Single Thread", |b, count| {
let mut rt = tokio::runtime::Builder::new()
.basic_scheduler()
});
group.bench_function(BenchmarkId::new("Async - Single Thread", count), |b| {
let rt = tokio::runtime::Builder::new_current_thread()
.build()
.unwrap();
let ids = (0..*count)
let ids = (0..count)
.map(|x| InputValue::scalar(x as i32))
.collect::<Vec<_>>();
let ids = InputValue::list(ids);
@ -62,14 +60,12 @@ fn bench_sync_vs_async_users_flat_instant(c: &mut Criterion) {
);
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))
.collect::<Vec<_>>();
let ids = InputValue::list(ids);
@ -81,8 +77,9 @@ fn bench_sync_vs_async_users_flat_instant(c: &mut Criterion) {
);
rt.block_on(f)
})
}),
);
});
}
group.finish();
}
criterion_group!(benches, bench_sync_vs_async_users_flat_instant);