-
Notifications
You must be signed in to change notification settings - Fork 627
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
35 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,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); | ||
}); | ||
} |