summaryrefslogtreecommitdiff
path: root/microbench/util.c
diff options
context:
space:
mode:
authorTristan Matthews <tmatth@videolan.org>2015-09-29 19:27:48 -0400
committerErik de Castro Lopo <erikd@mega-nerd.com>2015-09-30 18:58:39 +1000
commitab300d4b18da8410bbbd31c1782f27aa9f2fe6c0 (patch)
treedc3e9cdb13888aa8d45c5fa8ac4dbb62e7a65c95 /microbench/util.c
parentd91eb4ae756feb7fc1c4be6e465c58ca24471d22 (diff)
downloadflac-ab300d4b18da8410bbbd31c1782f27aa9f2fe6c0.tar.gz
microbench: add benchmarking code for Darwin
Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
Diffstat (limited to 'microbench/util.c')
-rw-r--r--microbench/util.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/microbench/util.c b/microbench/util.c
index cf19d234..0486590a 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