• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (C)2004 Landmark Graphics Corporation
2  * Copyright (C)2005 Sun Microsystems, Inc.
3  *
4  * This library is free software and may be redistributed and/or modified under
5  * the terms of the wxWindows Library License, Version 3.1 or (at your option)
6  * any later version.  The full license is in the LICENSE.txt file included
7  * with this distribution.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * wxWindows Library License for more details.
13  */
14 
15 #ifndef __RRTIMER_H__
16 #define __RRTIMER_H__
17 
18 #ifdef __cplusplus
19 
20 #ifdef _WIN32
21 #include <windows.h>
22 #else
23 #include <sys/time.h>
24 #endif
25 
26 class rrtimer
27 {
28 	public:
29 
rrtimer(void)30 		rrtimer(void) : t1(0.0)
31 		{
32 			#ifdef _WIN32
33 			highres=false;  tick=0.001;
34 			LARGE_INTEGER Frequency;
35 			if(QueryPerformanceFrequency(&Frequency)!=0)
36 			{
37 				tick=(double)1.0/(double)(Frequency.QuadPart);
38 				highres=true;
39 			}
40 			#endif
41 		}
42 
start(void)43 		void start(void)
44 		{
45 			t1=time();
46 		}
47 
time(void)48 		double time(void)
49 		{
50 			#ifdef _WIN32
51 			if(highres)
52 			{
53 				LARGE_INTEGER Time;
54 				QueryPerformanceCounter(&Time);
55 				return((double)(Time.QuadPart)*tick);
56 			}
57 			else
58 				return((double)GetTickCount()*tick);
59 			#else
60 			struct timeval __tv;
61 			gettimeofday(&__tv, (struct timezone *)NULL);
62 			return((double)(__tv.tv_sec)+(double)(__tv.tv_usec)*0.000001);
63 			#endif
64 		}
65 
elapsed(void)66 		double elapsed(void)
67 		{
68 			return time()-t1;
69 		}
70 
71 	private:
72 
73 		#ifdef _WIN32
74 		bool highres;  double tick;
75 		#endif
76 		double t1;
77 };
78 
79 #endif  // __cplusplus
80 
81 #ifdef _WIN32
82 
83 #include <windows.h>
84 
rrtime(void)85 __inline double rrtime(void)
86 {
87 	LARGE_INTEGER Frequency, Time;
88 	if(QueryPerformanceFrequency(&Frequency)!=0)
89 	{
90 		QueryPerformanceCounter(&Time);
91 		return (double)Time.QuadPart/(double)Frequency.QuadPart;
92 	}
93 	else return (double)GetTickCount()*0.001;
94 }
95 
96 #else
97 
98 #include <sys/time.h>
99 
100 #ifdef sun
101 #define __inline inline
102 #endif
103 
rrtime(void)104 static __inline double rrtime(void)
105 {
106 	struct timeval __tv;
107 	gettimeofday(&__tv, (struct timezone *)NULL);
108 	return((double)__tv.tv_sec+(double)__tv.tv_usec*0.000001);
109 }
110 
111 #endif
112 
113 #endif
114 
115