Subversion Repositories gelsvn

Rev

Rev 102 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
39 bj 1
#ifndef __OSTIMER_H__
2
#define __OSTIMER_H__
3
 
4
// Created by bdl 5. april 2002
5
// The purpose of this file is to make a timer function that is as 
6
// precise as posible on any given platform
7
 
8
#ifdef WIN32
9
#include <windows.h>
10
static LARGE_INTEGER	largeInteger;
11
#else
12
#include <sys/time.h>
13
#endif
14
 
15
namespace Util{
16
	class Timer {
17
#ifdef WIN32
18
		double freq;
19
		double start_count;
20
#else
21
		timeval start_time;
22
#endif
23
	public:
24
		void start() {
25
#ifdef WIN32
26
			QueryPerformanceFrequency(&largeInteger);
27
			freq = largeInteger.QuadPart;
28
			QueryPerformanceCounter(&largeInteger);
29
			start_count = largeInteger.QuadPart;
30
#else
31
			gettimeofday(&start_time,0);
32
#endif
33
		}
34
 
35
		float get_secs() {
36
#ifdef WIN32
37
			QueryPerformanceCounter(&largeInteger);
38
			double now_count = largeInteger.QuadPart;
39
			return (float)(now_count-start_count)/freq;
40
#else
41
			timeval now;
42
			gettimeofday(&now,0);
43
			return (now.tv_sec-start_time.tv_sec) + 
44
				(now.tv_usec-start_time.tv_usec)/1.0e6;
45
#endif
46
		}
47
	};
48
}
49
 
50
#endif