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: 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

View file

@ -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]]

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::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,74 +16,70 @@ fn bench_sync_vs_async_users_flat_instant(c: &mut Criterion) {
} }
"#; "#;
const SYNC_QUERY: &'static str = r#" // language=GraphQL
query Query($id: Int) { const SYNC_QUERY: &str = r#"
users_sync_instant(ids: [$id]!) { query Query($id: Int) {
id users_sync_instant(ids: [$id]!) {
kind id
username kind
email username
email
}
} }
"#;
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);
b.iter(|| {
j::execute_sync(
SYNC_QUERY,
vec![("ids".to_owned(), ids.clone())].into_iter().collect(),
)
})
});
group.bench_function(BenchmarkId::new("Async - Single Thread", count), |b| {
let rt = tokio::runtime::Builder::new_current_thread()
.build()
.unwrap();
let ids = (0..count)
.map(|x| InputValue::scalar(x as i32))
.collect::<Vec<_>>();
let ids = InputValue::list(ids);
b.iter(|| {
let f = j::execute(
ASYNC_QUERY,
vec![("ids".to_owned(), ids.clone())].into_iter().collect(),
);
rt.block_on(f)
})
});
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);
b.iter(|| {
let f = j::execute(
ASYNC_QUERY,
vec![("ids".to_owned(), ids.clone())].into_iter().collect(),
);
rt.block_on(f)
})
});
} }
"#; group.finish();
c.bench(
"Sync vs Async - Users Flat - Instant",
ParameterizedBenchmark::new(
"Sync",
|b, count| {
let ids = (0..*count)
.map(|x| InputValue::scalar(x as i32))
.collect::<Vec<_>>();
let ids = InputValue::list(ids);
b.iter(|| {
j::execute_sync(
SYNC_QUERY,
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()
.build()
.unwrap();
let ids = (0..*count)
.map(|x| InputValue::scalar(x as i32))
.collect::<Vec<_>>();
let ids = InputValue::list(ids);
b.iter(|| {
let f = j::execute(
ASYNC_QUERY,
vec![("ids".to_owned(), ids.clone())].into_iter().collect(),
);
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)
.map(|x| InputValue::scalar(x as i32))
.collect::<Vec<_>>();
let ids = InputValue::list(ids);
b.iter(|| {
let f = j::execute(
ASYNC_QUERY,
vec![("ids".to_owned(), ids.clone())].into_iter().collect(),
);
rt.block_on(f)
})
}),
);
} }
criterion_group!(benches, bench_sync_vs_async_users_flat_instant); criterion_group!(benches, bench_sync_vs_async_users_flat_instant);