C++获取函数执行时间

long GetMillisecondsCount()
{
    struct timeval tv;
    gettimeofday(&tv, NULL);
    return tv.tv_sec*1000 + tv.tv_usec/1000;
}

char * getTimeDiffString(long newTime, long oldTime) {
    long diff = newTime - oldTime;
    string timeString = std::to_string(diff/ 1000) + "." + std::to_string(diff % 1000) + "s";
    return const_cast(timeString.c_str());
}

 

你可能感兴趣的:(工具链)