/* * double total = systime(double &user, double &sys) * * Returns the elapsed user and system time in seconds. Function * returns the elapsed time (> or = to user+sys time). * */ #ifdef HAVE_CONFIG_H # include #endif #include #if !(defined(OS_WIN32) || LAPACK_OS_WIN32) # include #endif #define tim(tv) ((double) (tv.tv_sec + 1.e-6 * tv.tv_usec)) double systime(user,system) double *user, *system; { #if !(defined(OS_WIN32) || LAPACK_OS_WIN32) static struct rusage r; static struct timeval tv; # ifndef __STRICT_ANSI__ static struct timezone tz; # endif /* __STRICT_ANSI__ */ getrusage(RUSAGE_SELF, &r); *user = tim(r.ru_utime); *system = tim(r.ru_stime); # ifndef __STRICT_ANSI__ gettimeofday(&tv,&tz); # else /* __STRICT_ANSI__ */ gettimeofday(&tv,0); # endif /* __STRICT_ANSI__ */ return tim(tv); #else /* !(defined(OS_WIN32) || LAPACK_OS_WIN32) */ *user=1; *system=1; return 2; #endif /* !(defined(OS_WIN32) || LAPACK_OS_WIN32) */ } #ifdef TEST_SYSTIME #include main() { double systime(); double user[2], system[2], total[2]; char s[80]; double result= 0.0; int M; for (;;) { printf("Enter # of loops to perform (MxM):"); fflush(stdout); scanf("%d", &M); total[0] = systime(&user[0], &system[0]); /* some useless computation */ { int i; int j; for (i=0; i