1#![feature(test)]
2
3extern crate test;
4use crate::test::Bencher;
5
6use futures::executor::block_on;
7use futures::stream::{repeat, select, StreamExt};
8
9#[bench]
10fn select_streams(b: &mut Bencher) {
11 const STREAM_COUNT: usize = 10_000;
12
13 b.iter(|| {
14 let stream1 = repeat(1).take(STREAM_COUNT);
15 let stream2 = repeat(2).take(STREAM_COUNT);
16 let stream3 = repeat(3).take(STREAM_COUNT);
17 let stream4 = repeat(4).take(STREAM_COUNT);
18 let stream5 = repeat(5).take(STREAM_COUNT);
19 let stream6 = repeat(6).take(STREAM_COUNT);
20 let stream7 = repeat(7).take(STREAM_COUNT);
21 let count = block_on(async {
22 let count = select(
23 stream1,
24 select(
25 stream2,
26 select(stream3, select(stream4, select(stream5, select(stream6, stream7)))),
27 ),
28 )
29 .count()
30 .await;
31 count
32 });
33 assert_eq!(count, STREAM_COUNT * 7);
34 });
35}
36