#include <string>
inline long GetMillisecondsCount()
{
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec*1000 + tv.tv_usec/1000;
}
inline char * getTimeDiffString(long newTime, long oldTime) {
long diff = newTime - oldTime;
std::string timeString = std::to_string(diff/ 1000) + "." + std::to_string(diff % 1000) + "s";
return const_cast<char *>(timeString.c_str());
}
long time1 = GetMillisecondsCount();
…………………………………………………………………………………………
long time2 = GetMillisecondsCount();
LOGD(" cost = %s", getTimeDiffString(time2, time1));
struct timeval start_time{}, stop_time{};
gettimeofday(&start_time, nullptr);
....................
gettimeofday(&stop_time, nullptr);
double temptime = (get_us(stop_time) - get_us(start_time)) / 1000;
LOGD(" cost = %g ", temptime );