viewing paste Unknown #6715 | Plain text

Posted on the
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
void timer_cputimer_start(uint64 *start_time)
{
#if defined(WIN32)
        QueryPerformanceCounter((LARGE_INTEGER*)start_time);
#elif defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) && defined(CLOCK_PROCESS_CPUTIME_ID)
        struct timespec tval;
        clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tval);
        *start_time = tval.tv_sec * 1000 + tval.tv_nsec / 1000000;
#elif defined(CLOCKS_PER_SEC)
        *start_time = (uint64)clock();
#endif
}
 
double timer_cputimer_stop(uint64 start_time)
{
#if defined(WIN32)
        uint64 end_time, ldFreq;
        QueryPerformanceCounter((LARGE_INTEGER*)&end_time);
        QueryPerformanceFrequency((LARGE_INTEGER*)&ldFreq);
        return ((double)(end_time - start_time) / (double)ldFreq) * 1000.0;
#elif defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) && defined(CLOCK_PROCESS_CPUTIME_ID)
        struct timespec tval;
        uint64 end_time;
        clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tval);
        end_time = tval.tv_sec * 1000 + tval.tv_nsec / 1000000;
        return (double)(end_time - start_time);
#elif defined(CLOCKS_PER_SEC)
        uint64 end_time = (uint64)clock();
        return (double)(end_time - start_time)/(double)CLOCKS_PER_SEC;
#endif
}
Viewed 281 times, submitted by unknown.