Ask Your Question

Revision history [back]

It looks like the ros::Time is using the highest precision clock it can find, so perhaps it's more accurate than gettimeofday. The relevant code for not using sim_time appears to be: time.cpp:ros_walltime(uint32_t& sec, uint32_t& nsec). If we ignore all the WIN32 stuff, looks like the relevant snippet is here:

00101 #if HAS_CLOCK_GETTIME
00102     timespec start;
00103     clock_gettime(CLOCK_REALTIME, &start);
00104     sec  = start.tv_sec;
00105     nsec = start.tv_nsec;
00106 #else
00107     struct timeval timeofday;
00108     gettimeofday(&timeofday,NULL);
00109     sec  = timeofday.tv_sec;
00110     nsec = timeofday.tv_usec * 1000;
00111 #endif

I couldn't find anything with a quick Google search comparing the two, but it might be interesting to see if you have the same results as ros::Time if you use clock_gettime instead of gettimeofday in your profiling code.

If you need to get the current time for profiling reasons even when using sim_time, you should use ros::WallTime instead of ros::Time.