summaryrefslogtreecommitdiff
path: root/SpMV/include/timer.h
blob: cb513cb21974efbf72558506e4137ab055c3f83b (plain)
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
#pragma once

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

#if DFATOOL_TIMING

#define dfatool_printf(fmt, ...) do { printf(fmt, __VA_ARGS__); } while (0)

typedef struct Timer {
	struct timeval startTime;
	struct timeval endTime;
} Timer;

static void startTimer(Timer *timer)
{
	gettimeofday(&(timer->startTime), NULL);
}

static void stopTimer(Timer *timer)
{
	gettimeofday(&(timer->endTime), NULL);
}

static double getElapsedTime(Timer timer)
{
	return ((double)((timer.endTime.tv_sec - timer.startTime.tv_sec)
			 + (timer.endTime.tv_usec -
			    timer.startTime.tv_usec) / 1.0e6));
}

#else

#define dfatool_printf(fmt, ...) do {} while (0)

typedef int Timer;

static void startTimer(Timer* timer)
{
	(void)timer;
}

static void stopTimer(Timer* timer)
{
	(void)timer;
}

static double getElapsedTime(Timer timer)
{
	(void)timer;
	return 0.0;
}

#endif