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 enqueue
<void()>::callable_type
* fn
= enqueue
<void()>::call(el
, &function
, (void const *)(&function
));
45 //slow - approx. 4x slower
46 //enqueue<void()>::invokable_type * fn = enqueue<void()>::invoke(el, &function, (void const *)(&function));
48 boost::xtime start
, end
, now
;
49 boost::xtime_get(&start
, boost::TIME_UTC
);
51 for(int i
= 0; i
< 1000000; i
++) {
52 (*fn
)(); //this leaks when used with future pointer
53 //beacon::scoped_future<void> res((*fn)()); //this wraps the future pointer so that it doesn't leak
58 boost::xtime_get(&now
, boost::TIME_UTC
);
60 boost::thread::sleep(now
);
63 cout
<< el
.dequeue((void const *)(&function
)) << " calls" << endl
;
67 boost::xtime_get(&end
, boost::TIME_UTC
);
69 double diff
= end
.sec
- start
.sec
+ (end
.nsec
- start
.nsec
) / 1e9
;
71 cout
<< "time: " << diff
<< std::endl
;
72 cout
<< "times called: " << times_called
<< endl
;