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 select benchmark #2582

Merged
merged 1 commit into from
Mar 21, 2022
Merged
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
35 changes: 35 additions & 0 deletions futures-util/benches/select.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#![feature(test)]

extern crate test;
use crate::test::Bencher;

use futures::executor::block_on;
use futures::stream::{repeat, select, StreamExt};

#[bench]
fn select_streams(b: &mut Bencher) {
const STREAM_COUNT: usize = 10_000;

b.iter(|| {
let stream1 = repeat(1).take(STREAM_COUNT);
let stream2 = repeat(2).take(STREAM_COUNT);
let stream3 = repeat(3).take(STREAM_COUNT);
let stream4 = repeat(4).take(STREAM_COUNT);
let stream5 = repeat(5).take(STREAM_COUNT);
let stream6 = repeat(6).take(STREAM_COUNT);
let stream7 = repeat(7).take(STREAM_COUNT);
let count = block_on(async {
let count = select(
stream1,
select(
stream2,
select(stream3, select(stream4, select(stream5, select(stream6, stream7)))),
),
)
.count()
.await;
count
});
assert_eq!(count, STREAM_COUNT * 7);
});
}