主要用到的方式有两种:
(1)ros自带的计算时间
ros::Time t0 = ros::Time::now(); /*记时代码*/ ros::Time t1 = ros::Time::now(); ros::Duration d(t1 - t0); std::cout << "TIME in ms: " << d * 1000 << std::endl;
(2)调用ctime
#include<ctime> clock_t starttime,finishtime; starttime=clock(); /*记时代码*/ finishtime=clock(); std::cout << "TIME in ms: " << (finishtime-starttime)*1000/CLOCKS_PER_SEC << " ms" <<