microbench: Add fallback to gettimeofday()
Some operating systems such as OS/2 don't have any of the CLOCK* API functions so add gettimeofday() as a fallback. Signed-off-by: Dave Yeo <dave.r.yeo@gmail.com> Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
This commit is contained in:
parent
ab61102209
commit
50e7aea808
@ -371,6 +371,11 @@ AC_DEFINE(FLAC__HAS_DOCBOOK_TO_MAN)
|
||||
AH_TEMPLATE(FLAC__HAS_DOCBOOK_TO_MAN, [define if you have docbook-to-man or docbook2man])
|
||||
fi
|
||||
|
||||
AC_CHECK_LIB(rt, clock_gettime, have_clock_gettime=yes)
|
||||
if test x$have_clock_gettime = xyes; then
|
||||
AC_DEFINE(HAVE_CLOCK_GETTIME)
|
||||
fi
|
||||
|
||||
# only matters for x86
|
||||
AC_CHECK_PROGS(NASM, nasm)
|
||||
AM_CONDITIONAL(FLaC__HAS_NASM, test -n "$NASM")
|
||||
|
@ -95,7 +95,7 @@ benchmark_function (void (*testfunc) (void), unsigned count)
|
||||
return counter_diff (&start, &end) / count ;
|
||||
} /* benchmark_function */
|
||||
|
||||
#else
|
||||
#elif defined HAVE_CLOCK_GETTIME
|
||||
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
@ -131,6 +131,42 @@ benchmark_function (void (*testfunc) (void), unsigned count)
|
||||
return timespec_diff (&start, &end) / count ;
|
||||
} /* benchmark_function */
|
||||
|
||||
#else
|
||||
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
static double
|
||||
timeval_diff (const struct timeval * start, const struct timeval * end)
|
||||
{ struct timeval diff;
|
||||
|
||||
if (end->tv_usec - start->tv_usec < 0)
|
||||
{ diff.tv_sec = end->tv_sec - start->tv_sec - 1 ;
|
||||
diff.tv_usec = 1000000 + end->tv_usec - start->tv_usec ;
|
||||
}
|
||||
else
|
||||
{ diff.tv_sec = end->tv_sec - start->tv_sec ;
|
||||
diff.tv_usec = end->tv_usec-start->tv_usec ;
|
||||
} ;
|
||||
|
||||
return diff.tv_sec + 1e-6 * diff.tv_usec ;
|
||||
}
|
||||
|
||||
double
|
||||
benchmark_function (void (*testfunc) (void), unsigned count)
|
||||
{ struct timeval start, end;
|
||||
unsigned k ;
|
||||
|
||||
gettimeofday(&start, NULL);
|
||||
|
||||
for (k = 0 ; k < count ; k++)
|
||||
testfunc () ;
|
||||
|
||||
gettimeofday(&end, NULL);
|
||||
|
||||
return timeval_diff (&start, &end) / count ;
|
||||
} /* benchmark_function */
|
||||
|
||||
#endif
|
||||
|
||||
static int
|
||||
|
Loading…
x
Reference in New Issue
Block a user