linux 获取系统时间毫秒间隔

#include
#include
 
int main(){
    struct timeval start, end;
    double t1, t2;
    
    gettimeofday(&start, NULL);
 
    /*
        to do something
    */
 
    gettimeofday(&end, NULL);
 
    t1 = (double)start.tv_sec * 1000 + (double)start.tv_usec / 1000;
    t2 = (double)end.tv_sec * 1000 + (double)end.tv_usec / 1000;
 
    std::cout << t2 - t1 << std::endl;
    
    return 0;
}

 

你可能感兴趣的:(常用代码)