walltime.c

Go to the documentation of this file.
00001 #include <stdlib.h>
00002 
00003 #ifdef HAVE_CONFIG_H
00004 #include "config.h"
00005 #endif /* HAVE_CONFIG_H */
00006 
00007 #include "portability.h"
00008 
00015 double 
00016 walltime(void)
00017 {
00018   struct timeval tp;
00019   static long start=0, startu;
00020   if (!start)
00021   {
00022     gettimeofday(&tp, NULL);
00023     start = tp.tv_sec;
00024     startu = tp.tv_usec;
00025     return(0.0);
00026   }
00027   gettimeofday(&tp, NULL);
00028   return( ((double) (tp.tv_sec - start)) + (tp.tv_usec-startu)/1000000.0 );
00029 }
00030 
00038 double
00039 usertime(void)
00040 {
00041 #ifdef HAVE_GETRUSAGE
00042   struct rusage ru;
00043   static long start=0, startu;
00044   static int first=1;
00045 
00046   if(first) {
00047     first = 0;
00048     getrusage(RUSAGE_SELF, &ru);
00049     start = ru.ru_utime.tv_sec;
00050     startu = ru.ru_utime.tv_usec;
00051     return 0.0;
00052   }
00053 
00054   getrusage(RUSAGE_SELF, &ru);
00055 
00056   return( ((double) (ru.ru_utime.tv_sec - start)) + (ru.ru_utime.tv_usec-startu)/1000000.0 );
00057 #else
00058   return walltime();
00059 #endif
00060 }