From: yann.collet.73@gmail.com Date: Sat, 27 Oct 2012 18:26:58 +0000 (+0000) Subject: Corrected issue 39 : bench.c for NetBSD. Thanks to Thomas Klausner. X-Git-Tag: upstream/1.9.3~300 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=206f5f48cf4db19dad3de3adca1d95db335555e0;p=platform%2Fupstream%2Flz4.git Corrected issue 39 : bench.c for NetBSD. Thanks to Thomas Klausner. git-svn-id: https://lz4.googlecode.com/svn/trunk@81 650e7d94-2a16-8b24-b05c-7c0b3f6821cd --- diff --git a/bench.c b/bench.c index f379f99..a48029d 100644 --- a/bench.c +++ b/bench.c @@ -33,8 +33,9 @@ #define _LARGEFILE64_SOURCE // MSVC does not support S_ISREG -#ifndef S_ISREG -#define S_ISREG(x) (((x) & S_IFMT) == S_IFREG) +#if defined(_MSC_VER) +# define S_ISREG(x) (((x) & S_IFMT) == S_IFREG) +# define BMK_LEGACY_TIMER 1 #endif // GCC does not support _rotl outside of Windows @@ -46,11 +47,17 @@ //************************************** // Includes //************************************** -#include // malloc -#include // fprintf, fopen, ftello64 -#include // timeb -#include // stat64 -#include // stat64 +#include // malloc +#include // fprintf, fopen, ftello64 +#include // stat64 +#include // stat64 + +// Use ftime() if gettimeofday() is not available on your target +#if defined(BMK_LEGACY_TIMER) +# include // timeb, ftime +#else +# include // gettimeofday +#endif #include "lz4.h" #define COMPRESSOR0 LZ4_compress @@ -139,9 +146,11 @@ void BMK_SetNbIterations(int nbLoops) // Private functions //********************************************************* +#if defined(BMK_LEGACY_TIMER) + static int BMK_GetMilliStart() { - // Supposed to be portable + // Based on Legacy ftime() // Rolls over every ~ 12.1 days (0x100000/24/60/60) // Use GetMilliSpan to correct for rollover struct timeb tb; @@ -151,6 +160,21 @@ static int BMK_GetMilliStart() return nCount; } +#else + +static int BMK_GetMilliStart() +{ + // Based on newer gettimeofday() + // Use GetMilliSpan to correct for rollover + struct timeval tv; + int nCount; + gettimeofday(&tv, NULL); + nCount = (int) (tv.tv_usec/1000 + (tv.tv_sec & 0xfffff) * 1000); + return nCount; +} + +#endif + static int BMK_GetMilliSpan( int nTimeStart ) {