Measuring execution time of a call to system() in C++

后端 未结 3 1911
甜味超标
甜味超标 2021-01-14 02:46

I have found some code on measuring execution time here http://www.dreamincode.net/forums/index.php?showtopic=24685

However, it does not seem to work for calls to sy

3条回答
  •  清歌不尽
    2021-01-14 03:34

    Have you considered using gettimeofday?

    struct timeval tv;
    struct timeval start_tv;
    
    gettimeofday(&start_tv, NULL);
    
    system(something);
    
    double elapsed = 0.0;
    
    gettimeofday(&tv, NULL);
    elapsed = (tv.tv_sec - start_tv.tv_sec) +
      (tv.tv_usec - start_tv.tv_usec) / 1000000.0;
    

提交回复
热议问题