timer.cpp 487 Bytes
Newer Older
Kirill Terekhov's avatar
Fixes  
Kirill Terekhov committed
1

Kirill Terekhov's avatar
Kirill Terekhov committed
2 3
#if defined(_WIN32)
#include <windows.h>
Kirill Terekhov's avatar
Fixes  
Kirill Terekhov committed
4
	double Timer()
Kirill Terekhov's avatar
Kirill Terekhov committed
5 6 7 8 9
	{
		LARGE_INTEGER ticksPerSecond;
		LARGE_INTEGER tick;
		QueryPerformanceFrequency(&ticksPerSecond);
		QueryPerformanceCounter(&tick);
Kirill Terekhov's avatar
Fixes  
Kirill Terekhov committed
10
		return (double)tick.QuadPart/(double)ticksPerSecond.QuadPart;
Kirill Terekhov's avatar
Kirill Terekhov committed
11 12 13 14
	}
#else
#include <sys/time.h>
#include <stddef.h>
Alexander Danilov's avatar
Alexander Danilov committed
15
	double Timer()
Kirill Terekhov's avatar
Kirill Terekhov committed
16
	{
Kirill Terekhov's avatar
Fixes  
Kirill Terekhov committed
17
		double t1;
Kirill Terekhov's avatar
Kirill Terekhov committed
18 19
		struct timeval time;
		gettimeofday(&(time), NULL);
Kirill Terekhov's avatar
Fixes  
Kirill Terekhov committed
20
		t1 =  (double)time.tv_sec + (double)time.tv_usec/(1000.0*1000.0);
Kirill Terekhov's avatar
Kirill Terekhov committed
21 22 23
		return t1;
	}
#endif