Corrected issue 39 : bench.c for NetBSD. Thanks to Thomas Klausner.
authoryann.collet.73@gmail.com <yann.collet.73@gmail.com@650e7d94-2a16-8b24-b05c-7c0b3f6821cd>
Sat, 27 Oct 2012 18:26:58 +0000 (18:26 +0000)
committeryann.collet.73@gmail.com <yann.collet.73@gmail.com@650e7d94-2a16-8b24-b05c-7c0b3f6821cd>
Sat, 27 Oct 2012 18:26:58 +0000 (18:26 +0000)
git-svn-id: https://lz4.googlecode.com/svn/trunk@81 650e7d94-2a16-8b24-b05c-7c0b3f6821cd

bench.c

diff --git a/bench.c b/bench.c
index f379f99..a48029d 100644 (file)
--- a/bench.c
+++ b/bench.c
@@ -33,8 +33,9 @@
 #define _LARGEFILE64_SOURCE\r
 \r
 // MSVC does not support S_ISREG\r
-#ifndef S_ISREG\r
-#define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)\r
+#if defined(_MSC_VER)\r
+#  define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)\r
+#  define BMK_LEGACY_TIMER 1\r
 #endif\r
 \r
 // GCC does not support _rotl outside of Windows\r
 //**************************************\r
 // Includes\r
 //**************************************\r
-#include <stdlib.h>     // malloc\r
-#include <stdio.h>      // fprintf, fopen, ftello64\r
-#include <sys/timeb.h>  // timeb\r
-#include <sys/types.h>  // stat64\r
-#include <sys/stat.h>   // stat64\r
+#include <stdlib.h>      // malloc\r
+#include <stdio.h>       // fprintf, fopen, ftello64\r
+#include <sys/types.h>   // stat64\r
+#include <sys/stat.h>    // stat64\r
+\r
+// Use ftime() if gettimeofday() is not available on your target\r
+#if defined(BMK_LEGACY_TIMER)   \r
+#  include <sys/timeb.h>   // timeb, ftime\r
+#else\r
+#  include <sys/time.h>    // gettimeofday\r
+#endif\r
 \r
 #include "lz4.h"\r
 #define COMPRESSOR0 LZ4_compress\r
@@ -139,9 +146,11 @@ void BMK_SetNbIterations(int nbLoops)
 //  Private functions\r
 //*********************************************************\r
 \r
+#if defined(BMK_LEGACY_TIMER)\r
+\r
 static int BMK_GetMilliStart()\r
 {\r
-  // Supposed to be portable\r
+  // Based on Legacy ftime()\r
   // Rolls over every ~ 12.1 days (0x100000/24/60/60)\r
   // Use GetMilliSpan to correct for rollover\r
   struct timeb tb;\r
@@ -151,6 +160,21 @@ static int BMK_GetMilliStart()
   return nCount;\r
 }\r
 \r
+#else\r
+\r
+static int BMK_GetMilliStart()\r
+{\r
+  // Based on newer gettimeofday()\r
+  // Use GetMilliSpan to correct for rollover\r
+  struct timeval tv;\r
+  int nCount;\r
+  gettimeofday(&tv, NULL);\r
+  nCount = (int) (tv.tv_usec/1000 + (tv.tv_sec & 0xfffff) * 1000);\r
+  return nCount;\r
+}\r
+\r
+#endif\r
+\r
 \r
 static int BMK_GetMilliSpan( int nTimeStart )\r
 {\r