1#![feature(test)]
2
3extern crate test;
4use crate::test::Bencher;
5
6use futures::channel::oneshot;
7use futures::executor::block_on;
8use futures::future;
9use futures::stream::{FuturesUnordered, StreamExt};
10use futures::task::Poll;
11use std::collections::VecDeque;
12use std::thread;
13
14#[bench]
15fn oneshots(b: &mut Bencher) {
16 const NUM: usize = 10_000;
17
18 b.iter(|| {
19 let mut txs = VecDeque::with_capacity(NUM);
20 let mut rxs = FuturesUnordered::new();
21
22 for _ in 0..NUM {
23 let (tx, rx) = oneshot::channel();
24 txs.push_back(tx);
25 rxs.push(rx);
26 }
27
28 thread::spawn(move || {
29 while let Some(tx) = txs.pop_front() {
30 let _ = tx.send("hello");
31 }
32 });
33
34 block_on(future::poll_fn(move |cx| {
35 loop {
36 if let Poll::Ready(None) = rxs.poll_next_unpin(cx) {
37 break;
38 }
39 }
40 Poll::Ready(())
41 }))
42 });
43}
44