blob: 1fec653fa6b20cb02e58357526be12d439948141 (
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#![feature(test)]
extern crate futures;
extern crate test;
use futures::*;
use futures::executor::{Notify, NotifyHandle};
use futures::task::Task;
use test::Bencher;
fn notify_noop() -> NotifyHandle {
struct Noop;
impl Notify for Noop {
fn notify(&self, _id: usize) {}
}
const NOOP : &'static Noop = &Noop;
NotifyHandle::from(NOOP)
}
#[bench]
fn task_init(b: &mut Bencher) {
const NUM: u32 = 100_000;
struct MyFuture {
num: u32,
task: Option<Task>,
};
impl Future for MyFuture {
type Item = ();
type Error = ();
fn poll(&mut self) -> Poll<(), ()> {
if self.num == NUM {
Ok(Async::Ready(()))
} else {
self.num += 1;
if let Some(ref t) = self.task {
if t.will_notify_current() {
t.notify();
return Ok(Async::NotReady);
}
}
let t = task::current();
t.notify();
self.task = Some(t);
Ok(Async::NotReady)
}
}
}
let notify = notify_noop();
let mut fut = executor::spawn(MyFuture {
num: 0,
task: None,
});
b.iter(|| {
fut.get_mut().num = 0;
while let Ok(Async::NotReady) = fut.poll_future_notify(¬ify, 0) {
}
});
}
|