1 #ifndef TIMING_H
2 #define TIMING_H
3 
4 #include "hasrdtsc.h"
5 #include "hasgethr.h"
6 #include <sys/types.h>
7 #include <sys/time.h>
8 
9 typedef struct timeval timing_basic;
10 #define timing_basic_now(x) gettimeofday((x),(struct timezone *) 0)
11 #define timing_basic_diff(x,y) (1000.0 * ((x)->tv_usec - (double) (y)->tv_usec) + 1000000000.0 * ((x)->tv_sec - (double) (y)->tv_sec))
12 
13 
14 #ifdef HASRDTSC
15 
16 typedef struct { unsigned long t[2]; } timing;
17 #define timing_now(x) asm volatile(".byte 15;.byte 49" : "=a"((x)->t[0]),"=d"((x)->t[1]))
18 #define timing_diff(x,y) (((x)->t[0] - (double) (y)->t[0]) + 4294967296.0 * ((x)->t[1] - (double) (y)->t[1]))
19 
20 #else
21 #ifdef HASGETHRTIME
22 
23 typedef struct { hrtime_t t; } timing;
24 #define timing_now(x) ((x)->t = gethrtime())
25 #define timing_diff(x,y) ((double) ((x)->t - (y)->t))
26 
27 #else
28 
29 #define timing timing_basic
30 #define timing_now timing_basic_now
31 #define timing_diff timing_basic_diff
32 
33 #endif
34 #endif
35 
36 #endif
37