00001 #ifndef PHX_TIMER_H
00002 #define PHX_TIMER_H
00003
00004 #include <windows.h>
00005 #include <MMSystem.h>
00006
00007 namespace Phx {
00008
00009 class Timer
00010 {
00011 public:
00012
00013 static long getTime()
00014 {
00015 #ifdef WIN32
00016
00017 LARGE_INTEGER freq;
00018 if ( QueryPerformanceFrequency(&freq) )
00019 {
00020 LARGE_INTEGER counter;
00021 QueryPerformanceCounter( &counter );
00022 if ( freq.QuadPart >= 1000 )
00023 {
00024
00025 __int64 msDiv = __int64(freq.QuadPart) / __int64(1000);
00026 __int64 c = __int64(counter.QuadPart) / msDiv;
00027 return (long)c;
00028 }
00029 }
00030
00031 return timeGetTime();
00032
00033 #else
00034
00035 double t = double(clock()) / double(CLOCKS_PER_SEC) * 1000.0;
00036 return (long)t;
00037
00038 #endif
00039 }
00040
00041
00042 static int Sleep(long time)
00043 {
00044 #ifdef WIN32
00045
00046 ::Sleep(time);
00047
00048 #else
00049 struct timespec tv;
00050 tv.tv_sec = 0;
00051 tv.tv_nsec = time;
00052 nanosleep(&tv, 0);
00053
00054 #endif
00055 return 0;
00056 }
00057 };
00058
00059 }
00060
00061 #endif