blob: f8cd5fc390f36425114b5c8d5833dbfb7e613dc5 (
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 float getElapsedTime(Timer timer) {
return ((float) ((timer.endTime.tv_sec - timer.startTime.tv_sec)
+ (timer.endTime.tv_usec - timer.startTime.tv_usec)/1.0e6));
}
#endif
|