aboutsummaryrefslogtreecommitdiff
path: root/src/timer.h
blob: bee777b33a7400c6d205878ff9cc15a01a2d6fab (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//https://github.com/zuqqhi2/numerical_simulation/blob/master/multithread/laytrace/timer.h

#ifndef TIMER_H_
#define TIMER_H_

#include <stdio.h>
#include <sys/time.h>

static inline
unsigned long long gettimeval(void) {
  struct timeval tv;
  struct timezone tz;
  gettimeofday(&tv, &tz);
  return ((unsigned long long)tv.tv_sec)*1000000+tv.tv_usec;
}

static inline
void start_timer(unsigned long long *startt) {
  *startt = gettimeval();
  return;
}

static inline
unsigned long long stop_timer(unsigned long long *startt) {
  unsigned long long stopt = gettimeval();
  return (stopt>=*startt)?(stopt-*startt):(stopt);
}

#define print_timer(te) {printf("time of %s:%f[sec]\n", #te, (te*1.0e-3)/1000);}

#endif