timer.hpp 577 Bytes
Newer Older
ursular's avatar
ursular committed
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
// Timer for the HPCSE I course
//
#ifndef HPCSE_TIMER_HPP
#define HPCSE_TIMER_HPP

#include <sys/time.h>

class Timer {
public:
	Timer() {
		start_time.tv_sec  = 0;
		start_time.tv_usec = 0;
		stop_time.tv_sec   = 0;
		stop_time.tv_usec  = 0;
	}

	inline void start() {
		gettimeofday(&start_time, NULL);
	}

	inline void stop() {
		gettimeofday(&stop_time, NULL);
	}

	double get_timing() const {
		return (stop_time.tv_sec - start_time.tv_sec) + (stop_time.tv_usec - start_time.tv_usec)*1e-6;
	}

private:
	struct timeval start_time, stop_time;
};

#endif //HPCSE_TIMER_HPP