summaryrefslogtreecommitdiff
path: root/SpMV/support/timer.h
blob: 66e9842b0124a29de36167d96b6e564ec2ac4689 (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

#ifndef _TIMER_H_
#define _TIMER_H_

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

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));
}

#endif