2008/05/16

Tip with getrusage



#include

# getrusage is a POSIX funtion
# http://www.opengroup.org/onlinepubs/000095399/functions/getrusage.html

static struct rusage rusage_before;
static struct rusage rusage_after;

void
startTimer(void)
{
getrusage(RUSAGE_SELF, &rusage_before);
}


l_float32
stopTimer(void)
{
l_int32 tsec, tusec;

getrusage(RUSAGE_SELF, &rusage_after);

tsec = rusage_after.ru_utime.tv_sec - rusage_before.ru_utime.tv_sec;
tusec = rusage_after.ru_utime.tv_usec - rusage_before.ru_utime.tv_usec;

return (tsec + ((l_float32)tusec) / 1000000.0);
}

0 件のコメント: