32 #include "DGtal/base/Clock.h"
36 using namespace DGtal;
66 #if ( (defined(WIN32)) )
67 myFirstTick = clock();
68 if (myFirstTick == (clock_t) -1)
70 cerr <<
"[Clock::startClock] Erreur sur 'clock()'." << endl;
73 #ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
76 host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
77 clock_get_time(cclock, &mts);
78 mach_port_deallocate(mach_task_self(), cclock);
79 myTimerStart.tv_sec = mts.tv_sec;
80 myTimerStart.tv_nsec = mts.tv_nsec;
82 clock_gettime(CLOCK_REALTIME, &myTimerStart);
94 #if ( (defined(WIN32)) )
95 clock_t last_tick = clock();
96 if (last_tick == (clock_t) -1)
98 cerr <<
"[Clock::stopClock] Erreur sur 'clock()'." << endl;
100 return (
double) ((double) 1000.0 * (
double)(last_tick - myFirstTick)
101 / (
double) CLOCKS_PER_SEC);
103 struct timespec current;
105 #ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
108 host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
109 clock_get_time(cclock, &mts);
110 mach_port_deallocate(mach_task_self(), cclock);
111 current.tv_sec = mts.tv_sec;
112 current.tv_nsec = mts.tv_nsec;
114 clock_gettime(CLOCK_REALTIME, ¤t);
118 return (( current.tv_sec - myTimerStart.tv_sec) *1000 +
119 ( current.tv_nsec - myTimerStart.tv_nsec)/1000000.0);