Subversion Repositories gelsvn

Rev

Rev 102 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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