天天看點

測試程式耗時(毫秒級)

2020/06/24更新

#include <chrono>

typedef std::chrono::high_resolution_clock::time_point TimePoint;
#define TIMESTART std::chrono::high_resolution_clock::now()
#define TIMEELAPSED(x) std::chrono::duration_cast<std::chrono::milliseconds>(TIMESTART - x).count()

//使用示例
{
TimePoint time_start = TIMESTART;
/**< 這裡是待測代碼段 */
double elapsed_time = TIMEELAPSED(time_start);
}

           

測試精度在1ms,跨平台使用,使用c++代碼庫<chrono>