7 #include <beacon/event_loop.hpp>
8 #include <boost/bind.hpp>
9 #include <beacon/reference_countable.hpp>
12 using namespace beacon
;
14 unsigned times_called
= 0;
15 class inv
: public invokable
{
18 inv() : invokable(0) {
25 bool operator==(invokable
const & other
) {
26 return this == &other
;
34 int main(int argc
, char * argv
[]) {
43 boost::function
<void()> fn
= invoke_with_no_future
<void()>(el
, &function
, (void const *)(&function
));
45 //slow - approx. 5x slower
46 //boost::function<beacon::future<void> *()> fn = invoke_with_future_pointer<void()>(el, &function, (void const *)(&function));
48 //slow as well - no leaks
49 //boost::function<beacon::scoped_future<void> ()> fn = invoke_with_future_object<void()>(el, &function, (void const *)(&function));
51 boost::xtime start
, end
, now
;
52 boost::xtime_get(&start
, boost::TIME_UTC
);
54 for(int i
= 0; i
< 1000000; i
++) {
55 //el.enqueue(new inv);
56 fn(); //this leaks when used with future pointer
57 //beacon::scoped_future<void> res(fn()); //this wraps the future pointer so that it doesn't leak
60 boost::xtime_get(&now
, boost::TIME_UTC
);
62 boost::thread::sleep(now
);
65 cout
<< el
.dequeue((void const *)(&function
)) << " calls" << endl
;
69 boost::xtime_get(&end
, boost::TIME_UTC
);
71 double diff
= end
.sec
- start
.sec
+ (end
.nsec
- start
.nsec
) / 1e9
;
73 cout
<< "time: " << diff
<< std::endl
;
74 cout
<< "times called: " << times_called
<< endl
;