Skip to content

Commit

Permalink
Add select benchmark (#2582)
Browse files Browse the repository at this point in the history
  • Loading branch information
414owen authored Mar 21, 2022
1 parent 75de7a4 commit 800fab0
Showing 1 changed file with 35 additions and 0 deletions.
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);
});
}

0 comments on commit 800fab0

Please sign in to comment.