/* vi: set tabstop=4 shiftwidth=4: */ /* * $Id: timing.c,v 1.2 1996/12/28 22:11:23 schweikh Exp $ */ /* * functions for timing */ #include "config.h" #include "error.h" #include "timing.h" #if HAVE_GETRUSAGE #include #include #include #else /* not HAVE_GETRUSAGE */ #include #endif /* not HAVE_GETRUSAGE */ /* * The cpu_usage() semantics are intended to be the same as of * clock() with the exception of returning seconds in a double * instead of clock ticks in a clock_t. If the system supports * getrusage, this function will be preferred over ANSI's clock() * because for example on systems where CLOCKS_PER_SEC is 1000000 * clock() wraps after only 36 minutes (e.g. Solaris). */ double cpu_usage (void) { #if HAVE_GETRUSAGE struct rusage res; check_sys (getrusage (RUSAGE_SELF, &res) == 0); return res.ru_utime.tv_sec + res.ru_utime.tv_usec / 1000000.0 + res.ru_stime.tv_sec + res.ru_stime.tv_usec / 1000000.0; #else /* not HAVE_GETRUSAGE */ return clock () / (double) CLOCKS_PER_SEC; #endif /* not HAVE_GETRUSAGE */ }