-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.cpp
executable file
·51 lines (42 loc) · 1.15 KB
/
timer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**********************************************************************
|
| Bogart
| Chess Engine
|
| Copyright (C) 2009-2013 Dr.Kameleon
|
|**********************************************************************
| timer.cpp
|**********************************************************************/
#include "bogart.h"
//=======================================================
// Constructor
//=======================================================
Timer::Timer()
{
this->start = Timer::getTime();
}
//=======================================================
// Functions
//=======================================================
float Timer::timeElapsed()
{
timespec end = Timer::getTime();
return ((end.tv_sec - this->start.tv_sec)*1000) + ((end.tv_nsec-this->start.tv_nsec)/1000000);
}
timespec Timer::getTime()
{
timespec ts;
#ifdef __MACH__
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
clock_get_time(cclock, &mts);
mach_port_deallocate(mach_task_self(), cclock);
ts.tv_sec = mts.tv_sec;
ts.tv_nsec = mts.tv_nsec;
#else
clock_gettime(CLOCK_REALTIME, &ts);
#endif
return ts;
}