benchmark.cpp
Go to the documentation of this file.
00001 #include <nodelet/detail/callback_queue_manager.h>
00002 #include <nodelet/detail/callback_queue.h>
00003 #include <ros/callback_queue.h>
00004 #include <ros/time.h>
00005 
00006 #include <boost/thread.hpp>
00007 #include <boost/detail/atomic_count.hpp>
00008 #include <cstdio>
00009 
00010 using namespace nodelet::detail;
00011 using boost::detail::atomic_count;
00012 
00013 static const long NUM_CALLBACKS = 1e7;
00014 
00015 atomic_count g_count(NUM_CALLBACKS);
00016 boost::mutex g_mutex;
00017 boost::condition_variable g_cond;
00018 
00019 class MyCallback : public ros::CallbackInterface
00020 {
00021 public:
00022   ros::CallbackInterface::CallResult call()
00023   {
00024     if (--g_count == 0)
00025     {
00026       boost::mutex::scoped_lock lock(g_mutex);
00027       g_cond.notify_all();
00028     }
00029 
00030     return Success;
00031   }
00032 };
00033 typedef boost::shared_ptr<MyCallback> MyCallbackPtr;
00034 
00035 int main(int argc, char** argv)
00036 {
00037   CallbackQueueManager man;
00038   CallbackQueuePtr queue(new CallbackQueue(&man));
00039   man.addQueue(queue, true);
00040 
00041   double start = ros::WallTime::now().toSec();
00042 
00043   for (long i = 0; i < NUM_CALLBACKS; ++i)
00044   {
00045     MyCallbackPtr cb(new MyCallback);
00046     queue->addCallback(cb, 0);
00047   }
00048 
00049   {
00050     boost::mutex::scoped_lock lock(g_mutex);
00051     g_cond.wait(lock);
00052   }
00053 
00054   double end = ros::WallTime::now().toSec();
00055   printf("Total time = %.3f\n", end - start);
00056 
00057   return 0;
00058 }


test_nodelet
Author(s): Tully Foote
autogenerated on Sun Feb 17 2019 03:43:56