benchmark.cpp
Go to the documentation of this file.
3 #include <ros/callback_queue.h>
4 #include <ros/time.h>
5 
6 #include <boost/thread.hpp>
7 #include <boost/detail/atomic_count.hpp>
8 #include <cstdio>
9 
10 using namespace nodelet::detail;
11 using boost::detail::atomic_count;
12 
13 static const long NUM_CALLBACKS = 1e7;
14 
15 atomic_count g_count(NUM_CALLBACKS);
16 boost::mutex g_mutex;
18 
20 {
21 public:
23  {
24  if (--g_count == 0)
25  {
26  boost::mutex::scoped_lock lock(g_mutex);
27  g_cond.notify_all();
28  }
29 
30  return Success;
31  }
32 };
34 
35 int main(int argc, char** argv)
36 {
38  CallbackQueuePtr queue(new CallbackQueue(&man));
39  man.addQueue(queue, true);
40 
41  double start = ros::WallTime::now().toSec();
42 
43  for (long i = 0; i < NUM_CALLBACKS; ++i)
44  {
45  MyCallbackPtr cb(new MyCallback);
46  queue->addCallback(cb, 0);
47  }
48 
49  {
50  boost::mutex::scoped_lock lock(g_mutex);
51  g_cond.wait(lock);
52  }
53 
54  double end = ros::WallTime::now().toSec();
55  printf("Total time = %.3f\n", end - start);
56 
57  return 0;
58 }
ros::CallbackInterface::CallResult call()
Definition: benchmark.cpp:22
void notify_all() BOOST_NOEXCEPT
boost::shared_ptr< MyCallback > MyCallbackPtr
Definition: benchmark.cpp:33
void wait(unique_lock< mutex > &m)
boost::condition_variable g_cond
Definition: benchmark.cpp:17
atomic_count g_count(NUM_CALLBACKS)
void addQueue(const CallbackQueuePtr &queue, bool threaded)
boost::mutex g_mutex
Definition: benchmark.cpp:16
static WallTime now()
static const long NUM_CALLBACKS
Definition: benchmark.cpp:13
int main(int argc, char **argv)
Definition: benchmark.cpp:35


test_nodelet
Author(s): Tully Foote
autogenerated on Mon Feb 18 2019 03:26:50