Commit 50e7aea8 authored by dave.r.yeo's avatar dave.r.yeo Committed by Erik de Castro Lopo
Browse files

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.r.yeo's avatarDave Yeo <dave.r.yeo@gmail.com>
Signed-off-by: Erik de Castro Lopo's avatarErik de Castro Lopo <erikd@mega-nerd.com>
parent ab611022
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment