-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Criterion benchmark * Add benchmark * Fix CI
- Loading branch information
Showing
3 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |