On 02/08/16 03:25 AM, Erik de Castro Lopo wrote:
The configure stuff in the second seems overly complex. Is something like this:AC_CHECK_LIB(rt, clock_gettime, have_clock_gettime=yes) if test x$have_clock_gettime = xyes; then AC_DEFINE(HAVE_CLOCK_GETTIME) fi not sufficient? You can either test this and provide an updated patch or I can fix it here.
Yes, much simpler and works fine. Thanks Dave
From 6fe1a1c2a254e212227a208d241c9328469176c4 Mon Sep 17 00:00:00 2001 From: Dave Yeo <[email protected]> Date: Tue, 2 Feb 2016 20:19:59 -0800 Subject: [PATCH] Use gettimeofday() for benchmarking Some operating systems such as OS/2 don't have any of the CLOCK* API implemented Signed-off-by: Dave Yeo <[email protected]> --- configure.ac | 5 +++++ microbench/util.c | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 915869b..b577248 100644 --- a/configure.ac +++ b/configure.ac @@ -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") diff --git a/microbench/util.c b/microbench/util.c index ff1c3fb..dbd4bc1 100644 --- a/microbench/util.c +++ b/microbench/util.c @@ -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 -- 2.0.0
_______________________________________________ flac-dev mailing list [email protected] http://lists.xiph.org/mailman/listinfo/flac-dev
