Tristan Matthews
2015-Sep-29 23:27 UTC
[flac-dev] [PATCH 1/2] microbench: add benchmarking code for Darwin
--- microbench/util.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/microbench/util.c b/microbench/util.c index cf19d23..0486590 100644 --- a/microbench/util.c +++ b/microbench/util.c @@ -29,6 +29,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include <config.h> + #include <stdlib.h> #include "util.h" @@ -63,6 +65,36 @@ benchmark_function (void (*testfunc) (void), unsigned count) return counter_diff (&start, &end) / count ; } /* benchmark_function */ +#elif defined FLAC__SYS_DARWIN + +#include <mach/mach_time.h> + +static double +counter_diff (const uint64_t * start, const uint64_t * end) +{ + mach_timebase_info_data_t t_info; + mach_timebase_info(&t_info); + uint64_t duration = *end - *start; + + return duration * ((double)t_info.numer/(double)t_info.denom); +} + +double +benchmark_function (void (*testfunc) (void), unsigned count) +{ + uint64_t start, end; + unsigned k; + + start = mach_absolute_time(); + + for (k = 0 ; k < count ; k++) + testfunc(); + + end = mach_absolute_time(); + + return counter_diff (&start, &end) / count ; +} /* benchmark_function */ + #else #define _GNU_SOURCE -- 2.5.3
Tristan Matthews
2015-Sep-29 23:27 UTC
[flac-dev] [PATCH 2/2] microbench: remove duplicate define
--- microbench/util.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/microbench/util.c b/microbench/util.c index 0486590..94d8503 100644 --- a/microbench/util.c +++ b/microbench/util.c @@ -97,8 +97,6 @@ benchmark_function (void (*testfunc) (void), unsigned count) #else -#define _GNU_SOURCE - #include <time.h> #include <sys/time.h> -- 2.5.3
Erik de Castro Lopo
2015-Sep-30 09:18 UTC
[flac-dev] [PATCH 1/2] microbench: add benchmarking code for Darwin
Tristan Matthews wrote:> ---Both patches applied. Thanks. Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/