From 2bfb4dbce445eaa4dc06d3012a41eeb78628a06f Mon Sep 17 00:00:00 2001 From: Ben Laurie Date: Sat, 1 Jul 2000 16:25:20 +0000 Subject: [PATCH] Use up-to-date functions. --- apps/speed.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 7 deletions(-) diff --git a/apps/speed.c b/apps/speed.c index 7166606da7..9ef20872d9 100644 --- a/apps/speed.c +++ b/apps/speed.c @@ -82,16 +82,22 @@ #include #include -#if !defined(MSDOS) && (!defined(VMS) || defined(__DECC)) -#define TIMES +#if defined(__FreeBSD__) +# define USE_TOD +#elif !defined(MSDOS) && (!defined(VMS) || defined(__DECC)) +# define TIMES #endif #ifndef _IRIX -#include +# include #endif #ifdef TIMES -#include -#include +# include +# include +#endif +#ifdef USE_TOD +# include +# include #endif /* Depending on the VMS version, the tms structure is perhaps defined. @@ -203,7 +209,49 @@ static SIGRETTYPE sig_done(int sig) static double Time_F(int s, int usertime) { double ret; -#ifdef TIMES + +#ifdef USE_TOD + if(usertime) + { + static struct rusage tstart,tend; + + if (s == START) + { + getrusage(RUSAGE_SELF,&tstart); + return(0); + } + else + { + long i; + + getrusage(RUSAGE_SELF,&tend); + i=(long)tend.ru_utime.tv_usec-(long)tstart.ru_utime.tv_usec; + ret=((double)(tend.ru_utime.tv_sec-tstart.ru_utime.tv_sec)) + +((double)i)/1000000.0; + return((ret < 0.001)?0.001:ret); + } + } + else + { + static struct timeval tstart,tend; + long i; + + if (s == START) + { + gettimeofday(&tstart,NULL); + return(0); + } + else + { + gettimeofday(&tend,NULL); + i=(long)tend.tv_usec-(long)tstart.tv_usec; + ret=((double)(tend.tv_sec-tstart.tv_sec))+((double)i)/1000000.0; + return((ret < 0.001)?0.001:ret); + } + } +#else /* ndef USE_TOD */ + +# ifdef TIMES if (usertime) { static struct tms tstart,tend; @@ -221,7 +269,7 @@ static double Time_F(int s, int usertime) } } else -#endif /* times() */ +# endif /* times() */ { static struct timeb tstart,tend; long i; @@ -239,6 +287,7 @@ static double Time_F(int s, int usertime) return((ret < 0.001)?0.001:ret); } } +#endif } int MAIN(int, char **); -- 2.25.1