-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtiming.h
More file actions
55 lines (41 loc) · 866 Bytes
/
timing.h
File metadata and controls
55 lines (41 loc) · 866 Bytes
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#ifndef TIMING_H
#define TIMING_H
#if WITH_TIMING
#include <time.h>
#include <sys/time.h>
#include <stdio.h>
static
long long gpicker_hrtime_micros()
{
struct timeval tv;
gettimeofday(&tv, 0);
return tv.tv_sec * 1000000LL + tv.tv_usec;
}
typedef clock_t timing_t;
#define start_timing() gpicker_hrtime_micros()
static
void finish_timing(clock_t start, char *info)
{
long long ticks = gpicker_hrtime_micros() - start;
double msecs = ticks/1000.0;
fprintf(stderr, "%s took %g msecs\n", info, msecs);
}
#define timing_printf(...) fprintf(stderr, __VA_ARGS__)
#else
typedef int timing_t;
static inline
timing_t start_timing()
{
return 0;
}
static inline
void finish_timing(timing_t start, char *info)
{
}
static inline __attribute__((format (printf, 1, 2))) __attribute__((unused))
int timing_printf(const char *p, ...)
{
return 0;
}
#endif
#endif