summaryrefslogtreecommitdiff
path: root/microbench
diff options
context:
space:
mode:
authorErik de Castro Lopo <erikd@mega-nerd.com>2015-09-02 16:34:22 +1000
committerErik de Castro Lopo <erikd@mega-nerd.com>2015-09-02 16:34:22 +1000
commit451efca294ca8065e8f6de9a8796fb728a4df76c (patch)
tree713b4cc310d09a0e56e189fc39b365c3f7f87fa2 /microbench
parent98cab352a06ef7c84bfc0c69c45cc5e2d9be81ce (diff)
downloadflac-451efca294ca8065e8f6de9a8796fb728a4df76c.tar.gz
microbench/util.c: Win32 support
Diffstat (limited to 'microbench')
-rw-r--r--microbench/util.c41
1 files changed, 38 insertions, 3 deletions
diff --git a/microbench/util.c b/microbench/util.c
index b54305ce..cf19d234 100644
--- a/microbench/util.c
+++ b/microbench/util.c
@@ -29,14 +29,47 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <stdlib.h>
+#include "util.h"
+
+#if defined _WIN32
+
+#include <windows.h>
+
+static double
+counter_diff (const LARGE_INTEGER * start, const LARGE_INTEGER * end)
+{
+ LARGE_INTEGER diff, freq;
+
+ QueryPerformanceFrequency(&freq);
+ diff.QuadPart = end->QuadPart - start->QuadPart;
+
+ return (double)diff.QuadPart/(double)freq.QuadPart;
+}
+
+double
+benchmark_function (void (*testfunc) (void), unsigned count)
+{
+ LARGE_INTEGER start, end;
+ unsigned k;
+
+ QueryPerformanceCounter (&start) ;
+
+ for (k = 0 ; k < count ; k++)
+ testfunc();
+
+ QueryPerformanceCounter (&end) ;
+
+ return counter_diff (&start, &end) / count ;
+} /* benchmark_function */
+
+#else
+
#define _GNU_SOURCE
-#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
-#include "util.h"
-
static double
timespec_diff (const struct timespec * start, const struct timespec * end)
{ struct timespec difftime;
@@ -68,6 +101,8 @@ benchmark_function (void (*testfunc) (void), unsigned count)
return timespec_diff (&start, &end) / count ;
} /* benchmark_function */
+#endif
+
static int
double_cmp (const void * a, const void * b)
{ const double * pa = (double *) a ;