00001 #include <sys/time.h> 00002 #include <sys/resource.h> 00003 00004 double getwalltime(void) 00005 { 00006 struct timeval tv; 00007 gettimeofday(&tv, NULL); 00008 return tv.tv_sec * 1000.0 + tv.tv_usec/1000.0; 00009 } 00010 00011 double getcputime(double *utime, double *stime) 00012 { 00013 00014 struct rusage ru; 00015 getrusage(RUSAGE_SELF, &ru); 00016 *utime = ru.ru_utime.tv_sec * 1000.0 + ru.ru_utime.tv_usec/1000.0; 00017 *stime = ru.ru_stime.tv_sec * 1000.0 + ru.ru_stime.tv_usec/1000.0; 00018 return *utime + *stime; 00019 }