• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  #include "BenchSysTimer_posix.h"
2  
3  //Time
4  #include <time.h>
5  
intervalInMSec(const timespec start_clock,const timespec end_clock)6  static double intervalInMSec(const timespec start_clock
7                             , const timespec end_clock)
8  {
9      double duration_clock;
10      if ((end_clock.tv_nsec - start_clock.tv_nsec) < 0) {
11          duration_clock = (end_clock.tv_sec - start_clock.tv_sec-1)*1000;
12          duration_clock += (1000000000 + end_clock.tv_nsec - start_clock.tv_nsec)
13                             / 1000000.0;
14      } else {
15          duration_clock = (end_clock.tv_sec - start_clock.tv_sec)*1000;
16          duration_clock += (end_clock.tv_nsec - start_clock.tv_nsec) / 1000000.0;
17      }
18      return duration_clock;
19  }
20  
startWall()21  void BenchSysTimer::startWall() {
22      if (-1 == clock_gettime(CLOCK_MONOTONIC, &this->fWall)) {
23          timespec none = {0, 0};
24          this->fWall = none;
25      }
26  }
startCpu()27  void BenchSysTimer::startCpu() {
28      if (-1 == clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &this->fCpu)) {
29          timespec none = {0, 0};
30          this->fCpu = none;
31      }
32  }
33  
endCpu()34  double BenchSysTimer::endCpu() {
35      timespec end_cpu;
36      if (-1 == clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end_cpu)) {
37          timespec none = {0, 0};
38          end_cpu = none;
39      }
40      return intervalInMSec(this->fCpu, end_cpu);
41  }
42  
endWall()43  double BenchSysTimer::endWall() {
44      timespec end_wall;
45      if (-1 == clock_gettime(CLOCK_MONOTONIC, &end_wall)) {
46          timespec none = {0, 0};
47          end_wall = none;
48      }
49      return intervalInMSec(this->fWall, end_wall);
50  }
51