Skip to content
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

Add benchmarks #26

Merged
merged 3 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
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
15 changes: 15 additions & 0 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
on:
- pull_request
- workflow_dispatch

name: criterion benchmark
jobs:
runBenchmark:
name: run benchmark
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: boa-dev/criterion-compare-action@v3
with:
# Use the base branch name as the branch to compare with
branchName: ${{ github.base_ref }}
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,22 @@ version = "0.6.1"
edition = "2018"
repository = "https://github.com/mre/futures-batch"

[lib]
# https://bheisler.github.io/criterion.rs/book/faq.html#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options
bench = false

[dependencies]
futures = { version = "0.3", features = ["async-await"] }
pin-utils = "0.1.0"
futures-timer = "3.0.2"

[dev-dependencies]
tokio = { version = "1.22", features = ["macros", "rt-multi-thread"] }
criterion = { version = "0.4", features = ["html_reports", "async_tokio"] }

[dev-dependencies.doc-comment]
version = "0.3"

[[bench]]
name = "futures_batch_benchmark"
harness = false
25 changes: 25 additions & 0 deletions benches/futures_batch_benchmark.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use futures::stream::{self, Stream};
use futures_batch::ChunksTimeoutStreamExt;
use std::time::Duration;
use tokio::runtime::Runtime;

async fn batch(stream: impl Stream<Item = i32> + Unpin) {
let _ = stream.chunks_timeout(5, Duration::new(10, 0));
}

fn criterion_benchmark(c: &mut Criterion) {
let rt = Runtime::new().unwrap();

let mut group = c.benchmark_group("futures_batch");
for &size in &[1000, 10_000, 100_000, 1_000_000, 10_000_000] {
group.throughput(Throughput::Bytes(size as u64));
group.bench_with_input(BenchmarkId::from_parameter(size), &size, |b, &size| {
b.to_async(&rt).iter(|| batch(stream::iter(0..size)));
});
}
group.finish();
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
Loading