summaryrefslogtreecommitdiffstats
path: root/third_party/rust/futures-util/benches/select.rs
blob: 5410a952997072dab30e910831cc367d591512eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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);
    });
}