linux c++ code統計耗時

#include <time.h>
#define MICRO_IN_SECOND 1000000
#define NANOS_IN_SECOND 1000000000

double currentTimeInMiliSeconds() {
    struct timespec res;
    double ret = 0;
    clock_gettime(CLOCK_MONOTONIC, &res);
    ret = (double)(res.tv_sec * NANOS_IN_SECOND + res.tv_nsec) / MICRO_IN_SECOND;

    return ret;
}

double t1 = currentTimeInMiliSeconds();

//需要統計時間的code

double t2 = currentTimeInMiliSeconds();
    cout<<"ProcessFrameArrive time "  << t2 - t1 << endl;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章