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;
17 boost::condition_variable g_cond;
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 }
g_count
atomic_count g_count(NUM_CALLBACKS)
nodelet::detail
boost::shared_ptr
time.h
TimeBase< WallTime, WallDuration >::toSec
double toSec() const
main
int main(int argc, char **argv)
Definition: benchmark.cpp:35
ros::CallbackInterface::CallResult
CallResult
MyCallback::call
ros::CallbackInterface::CallResult call()
Definition: benchmark.cpp:22
nodelet::detail::CallbackQueue
MyCallbackPtr
boost::shared_ptr< MyCallback > MyCallbackPtr
Definition: benchmark.cpp:33
nodelet::detail::CallbackQueueManager
ros::WallTime::now
static WallTime now()
callback_queue_manager.h
ros::CallbackInterface
g_cond
boost::condition_variable g_cond
Definition: benchmark.cpp:17
callback_queue.h
NUM_CALLBACKS
static const long NUM_CALLBACKS
Definition: benchmark.cpp:13
start
ROSCPP_DECL void start()
MyCallback
Definition: benchmark.cpp:19
g_mutex
boost::mutex g_mutex
Definition: benchmark.cpp:16
nodelet::detail::CallbackQueueManager::addQueue
void addQueue(const CallbackQueuePtr &queue, bool threaded)


test_nodelet
Author(s): Tully Foote, Michael Carroll
autogenerated on Fri Jan 12 2024 03:40:44