CPU time

#include <sys/resource.h>
#include <sys/time.h>

unsigned GetSystemTime()
{
    rusage ru;
    if(::getrusage(RUSAGE_SELF, &ru) != -1)
    {
        return (unsigned)(ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec);
    }

    // fallback
    timeval time;
    ::gettimeofday(&time, 0);

    return (unsigned)(time.tv_sec * 1000000 + time.tv_usec);
}

Leave a Reply

Your email address will not be published. Required fields are marked *