removed kdevelop projects files from repo in master branch
[beacon-ss.git] / event_loop_test.cpp
blob58e4931ac240aff24dc9d7b9330def698eb9a704
2 #ifdef HAVE_CONFIG_H
3 #include <config.h>
4 #endif
6 #include <iostream>
7 #include <beacon/event_loop.hpp>
8 #include <boost/bind.hpp>
9 #include <beacon/reference_countable.hpp>
11 using namespace std;
12 using namespace beacon;
14 unsigned times_called = 0;
15 class inv : public invokable {
16 public:
18 inv() : invokable(0) {
21 void invoke() {
22 times_called++;
25 bool operator==(invokable const & other) {
26 return this == &other;
30 void function() {
31 times_called++;
34 int main(int argc, char * argv[]) {
36 event_loop el;
38 el.start();
40 inv in;
42 beacon::invokable::token_ptr token(new invocation_token);
44 //fast
45 //enqueue<void()>::callable<void(*)()>::type fn = enqueue<void()>::call(el, &function, token);
47 //slow - approx. 4x slower
48 enqueue<void()>::invokable<void(*)()>::type fn = enqueue<void()>::invoke(el, &function, token);
50 boost::xtime start, end, now;
51 boost::xtime_get(&start, boost::TIME_UTC);
53 for(int i = 0; i < 1000000; i++) {
54 fn();
58 // boost::xtime_get(&now, boost::TIME_UTC);
59 // now.nsec += 1000;
60 // boost::thread::sleep(now);
62 // cout << "dequing ";
63 // cout << el.dequeue(token) << " calls" << endl;
65 el.join();
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;
73 return EXIT_SUCCESS;