Subversion Repositories gelsvn

Rev

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

Rev 595 Rev 630
1
/* ----------------------------------------------------------------------- *
1
/* ----------------------------------------------------------------------- *
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
3
 * Copyright (C) the authors and DTU Informatics
3
 * Copyright (C) the authors and DTU Informatics
4
 * For license and list of authors, see ../../doc/intro.pdf
4
 * For license and list of authors, see ../../doc/intro.pdf
5
 * ----------------------------------------------------------------------- */
5
 * ----------------------------------------------------------------------- */
6
 
6
 
7
/**
7
/**
8
 * @file Timer.h
8
 * @file Timer.h
9
 * @brief Wall clock timing.
9
 * @brief Wall clock timing.
10
 */
10
 */
11
 
11
 
12
#ifndef __UTIL_OSTIMER_H__
12
#ifndef __UTIL_OSTIMER_H__
13
#define __UTIL_OSTIMER_H__
13
#define __UTIL_OSTIMER_H__
14
 
14
 
15
// Created by bdl 5. april 2002
15
// Created by bdl 5. april 2002
16
// The purpose of this file is to make a timer function that is as 
16
// The purpose of this file is to make a timer function that is as 
17
// precise as posible on any given platform
17
// precise as posible on any given platform
18
#if (_MSC_VER >= 1200)
18
#if (_MSC_VER >= 1200)
19
#pragma warning (disable: 4244)
19
#pragma warning (disable: 4244)
20
#endif
20
#endif
21
#ifdef WIN32
21
#ifdef WIN32
22
#include <windows.h>
22
#include <windows.h>
23
static LARGE_INTEGER	largeInteger;
23
static LARGE_INTEGER	largeInteger;
24
#else
24
#else
25
#include <sys/time.h>
25
#include <sys/time.h>
26
#endif
26
#endif
27
 
27
 
28
namespace Util{
28
namespace Util{
29
	class Timer {
29
	class Timer {
30
#ifdef WIN32
30
#ifdef WIN32
31
		double freq;
31
		double freq;
32
		double start_count;
32
		double start_count;
33
#else
33
#else
34
		timeval start_time;
34
		timeval start_time;
35
#endif
35
#endif
36
	public:
36
	public:
37
		void start() {
37
		void start() {
38
#ifdef WIN32
38
#ifdef WIN32
39
			QueryPerformanceFrequency(&largeInteger);
39
			QueryPerformanceFrequency(&largeInteger);
40
			freq = largeInteger.QuadPart;
40
			freq = largeInteger.QuadPart;
41
			QueryPerformanceCounter(&largeInteger);
41
			QueryPerformanceCounter(&largeInteger);
42
			start_count = largeInteger.QuadPart;
42
			start_count = largeInteger.QuadPart;
43
#else
43
#else
44
			gettimeofday(&start_time,0);
44
			gettimeofday(&start_time,0);
45
#endif
45
#endif
46
		}
46
		}
47
 
47
 
48
		float get_secs() {
48
		float get_secs() {
49
#ifdef WIN32
49
#ifdef WIN32
50
			QueryPerformanceCounter(&largeInteger);
50
			QueryPerformanceCounter(&largeInteger);
51
			double now_count = largeInteger.QuadPart;
51
			double now_count = largeInteger.QuadPart;
52
			return (float)((now_count-start_count)/freq);
52
			return (float)((now_count-start_count)/freq);
53
#else
53
#else
54
			timeval now;
54
			timeval now;
55
			gettimeofday(&now,0);
55
			gettimeofday(&now,0);
56
			return (now.tv_sec-start_time.tv_sec) + 
56
			return (now.tv_sec-start_time.tv_sec) + 
57
				(now.tv_usec-start_time.tv_usec)/1.0e6;
57
				(now.tv_usec-start_time.tv_usec)/1.0e6;
58
#endif
58
#endif
59
		}
59
		}
60
	};
60
	};
61
}
61
}
62
 
62
 
63
#endif
63
#endif
64
 
64