diff --git a/programs/bench.c b/programs/bench.c index 2f30c65a..5d2568f1 100644 --- a/programs/bench.c +++ b/programs/bench.c @@ -34,7 +34,6 @@ #include /* malloc, free */ #include /* memset */ #include /* fprintf, fopen */ -#include /* clock_t, clock, CLOCKS_PER_SEC */ #include "mem.h" #define ZSTD_STATIC_LINKING_ONLY @@ -72,12 +71,13 @@ static U32 g_compressibilityDefault = 50; #define DISPLAYLEVEL(l, ...) if (g_displayLevel>=l) { DISPLAY(__VA_ARGS__); } static int g_displayLevel = 2; /* 0 : no display; 1: errors; 2 : + result + interaction + warnings; 3 : + progression; 4 : + information */ -#define DISPLAYUPDATE(l, ...) if (g_displayLevel>=l) { \ - if ((clock() - g_time > refreshRate) || (g_displayLevel>=4)) \ - { g_time = clock(); DISPLAY(__VA_ARGS__); \ - if (g_displayLevel>=4) fflush(stderr); } } -static const clock_t refreshRate = CLOCKS_PER_SEC * 15 / 100; -static clock_t g_time = 0; +static const U64 g_refreshRate = SEC_TO_MICRO / 6; +static UTIL_time_t g_displayClock = UTIL_TIME_INITIALIZER; + +#define DISPLAYUPDATE(l, ...) { if (g_displayLevel>=l) { \ + if ((UTIL_clockSpanMicro(g_displayClock) > g_refreshRate) || (g_displayLevel>=4)) \ + { g_displayClock = UTIL_getTime(); DISPLAY(__VA_ARGS__); \ + if (g_displayLevel>=4) fflush(stderr); } } } /* ************************************* diff --git a/programs/dibio.c b/programs/dibio.c index dea3ec44..112259dd 100644 --- a/programs/dibio.c +++ b/programs/dibio.c @@ -26,7 +26,6 @@ #include /* malloc, free */ #include /* memset */ #include /* fprintf, fopen, ftello64 */ -#include /* clock_t, clock, CLOCKS_PER_SEC */ #include /* errno */ #include "mem.h" /* read */ @@ -55,15 +54,13 @@ static const size_t g_maxMemory = (sizeof(size_t) == 4) ? (2 GB - 64 MB) : ((siz #define DISPLAY(...) fprintf(stderr, __VA_ARGS__) #define DISPLAYLEVEL(l, ...) if (displayLevel>=l) { DISPLAY(__VA_ARGS__); } -#define DISPLAYUPDATE(l, ...) if (displayLevel>=l) { \ - if ((DIB_clockSpan(g_time) > refreshRate) || (displayLevel>=4)) \ - { g_time = clock(); DISPLAY(__VA_ARGS__); \ - if (displayLevel>=4) fflush(stderr); } } -static const clock_t refreshRate = CLOCKS_PER_SEC * 2 / 10; -static clock_t g_time = 0; - -static clock_t DIB_clockSpan(clock_t nPrevious) { return clock() - nPrevious; } +static const U64 g_refreshRate = SEC_TO_MICRO / 6; +static UTIL_time_t g_displayClock = UTIL_TIME_INITIALIZER; +#define DISPLAYUPDATE(l, ...) { if (displayLevel>=l) { \ + if ((UTIL_clockSpanMicro(g_displayClock) > g_refreshRate) || (displayLevel>=4)) \ + { g_displayClock = UTIL_getTime(); DISPLAY(__VA_ARGS__); \ + if (displayLevel>=4) fflush(stderr); } } } /*-************************************* * Exceptions diff --git a/programs/fileio.c b/programs/fileio.c index eb004f91..c9b6b04e 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -29,7 +29,6 @@ #include /* fprintf, fopen, fread, _fileno, stdin, stdout */ #include /* malloc, free */ #include /* strcmp, strlen */ -#include /* clock */ #include /* errno */ #if defined (_MSC_VER) @@ -40,6 +39,7 @@ #include "bitstream.h" #include "mem.h" #include "fileio.h" +#include "util.h" #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_magicNumber, ZSTD_frameHeaderSize_max */ #include "zstd.h" #if defined(ZSTD_GZCOMPRESS) || defined(ZSTD_GZDECOMPRESS) @@ -81,12 +81,13 @@ static int g_displayLevel = 2; /* 0 : no display; 1: errors; 2: + result + interaction + warnings; 3: + progression; 4: + information */ void FIO_setNotificationLevel(unsigned level) { g_displayLevel=level; } +static const U64 g_refreshRate = SEC_TO_MICRO / 6; +static UTIL_time_t g_displayClock = UTIL_TIME_INITIALIZER; + #define DISPLAYUPDATE(l, ...) { if (g_displayLevel>=l) { \ - if ((clock() - g_time > refreshRate) || (g_displayLevel>=4)) \ - { g_time = clock(); DISPLAY(__VA_ARGS__); \ + if ((UTIL_clockSpanMicro(g_displayClock) > g_refreshRate) || (g_displayLevel>=4)) \ + { g_displayClock = UTIL_getTime(); DISPLAY(__VA_ARGS__); \ if (g_displayLevel>=4) fflush(stderr); } } } -static const clock_t refreshRate = CLOCKS_PER_SEC * 15 / 100; -static clock_t g_time = 0; #undef MIN /* in case it would be already defined */ #define MIN(a,b) ((a) < (b) ? (a) : (b)) diff --git a/programs/util.h b/programs/util.h index e44d7459..37098f2f 100644 --- a/programs/util.h +++ b/programs/util.h @@ -118,6 +118,7 @@ static int g_utilDisplayLevel; * Time functions ******************************************/ #if defined(_WIN32) /* Windows */ + #define UTIL_TIME_INITIALIZER { { 0, 0 } } typedef LARGE_INTEGER UTIL_time_t; UTIL_STATIC UTIL_time_t UTIL_getTime(void) { UTIL_time_t x; QueryPerformanceCounter(&x); return x; } UTIL_STATIC U64 UTIL_getSpanTimeMicro(UTIL_time_t clockStart, UTIL_time_t clockEnd) @@ -144,6 +145,7 @@ static int g_utilDisplayLevel; } #elif defined(__APPLE__) && defined(__MACH__) #include + #define UTIL_TIME_INITIALIZER 0 typedef U64 UTIL_time_t; UTIL_STATIC UTIL_time_t UTIL_getTime(void) { return mach_absolute_time(); } UTIL_STATIC U64 UTIL_getSpanTimeMicro(UTIL_time_t clockStart, UTIL_time_t clockEnd) @@ -168,6 +170,7 @@ static int g_utilDisplayLevel; } #elif (PLATFORM_POSIX_VERSION >= 200112L) #include + #define UTIL_TIME_INITIALIZER { 0, 0 } typedef struct timespec UTIL_freq_t; typedef struct timespec UTIL_time_t; UTIL_STATIC UTIL_time_t UTIL_getTime(void) @@ -207,11 +210,13 @@ static int g_utilDisplayLevel; } #else /* relies on standard C (note : clock_t measurements can be wrong when using multi-threading) */ typedef clock_t UTIL_time_t; + #define UTIL_TIME_INITIALIZER 0 UTIL_STATIC UTIL_time_t UTIL_getTime(void) { return clock(); } UTIL_STATIC U64 UTIL_getSpanTimeMicro(UTIL_time_t clockStart, UTIL_time_t clockEnd) { return 1000000ULL * (clockEnd - clockStart) / CLOCKS_PER_SEC; } UTIL_STATIC U64 UTIL_getSpanTimeNano(UTIL_time_t clockStart, UTIL_time_t clockEnd) { return 1000000000ULL * (clockEnd - clockStart) / CLOCKS_PER_SEC; } #endif +#define SEC_TO_MICRO 1000000 /* returns time span in microseconds */ UTIL_STATIC U64 UTIL_clockSpanMicro( UTIL_time_t clockStart ) diff --git a/tests/decodecorpus.c b/tests/decodecorpus.c index e697e519..40765311 100644 --- a/tests/decodecorpus.c +++ b/tests/decodecorpus.c @@ -14,8 +14,8 @@ #include #include #include -#include +#include "util.h" #include "zstd.h" #include "zstd_internal.h" #include "mem.h" @@ -49,20 +49,16 @@ static U32 g_displayLevel = 2; #define DISPLAYUPDATE(...) \ do { \ - if ((clockSpan(g_displayClock) > g_refreshRate) || \ + if ((UTIL_clockSpanMicro(g_displayClock) > g_refreshRate) || \ (g_displayLevel >= 4)) { \ - g_displayClock = clock(); \ + g_displayClock = UTIL_getTime(); \ DISPLAY(__VA_ARGS__); \ if (g_displayLevel >= 4) fflush(stderr); \ } \ } while (0) -static const clock_t g_refreshRate = CLOCKS_PER_SEC / 6; -static clock_t g_displayClock = 0; -static clock_t clockSpan(clock_t cStart) -{ - return clock() - cStart; /* works even when overflow; max span ~ 30mn */ -} +static const U64 g_refreshRate = SEC_TO_MICRO / 6; +static UTIL_time_t g_displayClock = UTIL_TIME_INITIALIZER; #define CHECKERR(code) \ do { \ @@ -1531,14 +1527,14 @@ static int runTestMode(U32 seed, unsigned numFiles, unsigned const testDurationS { unsigned fnum; - clock_t const startClock = clock(); - clock_t const maxClockSpan = testDurationS * CLOCKS_PER_SEC; + UTIL_time_t const startClock = UTIL_getTime(); + U64 const maxClockSpan = testDurationS * SEC_TO_MICRO; if (numFiles == 0 && !testDurationS) numFiles = 1; DISPLAY("seed: %u\n", seed); - for (fnum = 0; fnum < numFiles || clockSpan(startClock) < maxClockSpan; fnum++) { + for (fnum = 0; fnum < numFiles || UTIL_clockSpanMicro(startClock) < maxClockSpan; fnum++) { if (fnum < numFiles) DISPLAYUPDATE("\r%u/%u ", fnum, numFiles); else diff --git a/tests/fuzzer.c b/tests/fuzzer.c index be9dc3e0..46671a15 100644 --- a/tests/fuzzer.c +++ b/tests/fuzzer.c @@ -25,7 +25,6 @@ #include /* free */ #include /* fgets, sscanf */ #include /* strcmp */ -#include /* clock_t */ #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_compressContinue, ZSTD_compressBlock */ #include "zstd.h" /* ZSTD_VERSION_STRING */ #include "zstd_errors.h" /* ZSTD_getErrorCode */ @@ -36,6 +35,7 @@ #include "mem.h" #define XXH_STATIC_LINKING_ONLY #include "xxhash.h" /* XXH64 */ +#include "util.h" /*-************************************ @@ -56,25 +56,22 @@ static const U32 nbTestsDefault = 30000; #define DISPLAYLEVEL(l, ...) if (g_displayLevel>=l) { DISPLAY(__VA_ARGS__); } static U32 g_displayLevel = 2; -#define DISPLAYUPDATE(l, ...) if (g_displayLevel>=l) { \ - if ((FUZ_clockSpan(g_displayClock) > g_refreshRate) || (g_displayLevel>=4)) \ - { g_displayClock = clock(); DISPLAY(__VA_ARGS__); \ - if (g_displayLevel>=4) fflush(stdout); } } -static const clock_t g_refreshRate = CLOCKS_PER_SEC / 6; -static clock_t g_displayClock = 0; +static const U64 g_refreshRate = SEC_TO_MICRO / 6; +static UTIL_time_t g_displayClock = UTIL_TIME_INITIALIZER; +#define DISPLAYUPDATE(l, ...) if (g_displayLevel>=l) { \ + if ((UTIL_clockSpanMicro(g_displayClock) > g_refreshRate) || (g_displayLevel>=4)) \ + { g_displayClock = UTIL_getTime(); DISPLAY(__VA_ARGS__); \ + if (g_displayLevel>=4) fflush(stderr); } } /*-******************************************************* * Fuzzer functions *********************************************************/ +#undef MIN +#undef MAX #define MIN(a,b) ((a)<(b)?(a):(b)) #define MAX(a,b) ((a)>(b)?(a):(b)) -static clock_t FUZ_clockSpan(clock_t cStart) -{ - return clock() - cStart; /* works even when overflow; max span ~ 30mn */ -} - #define FUZ_rotl32(x,r) ((x << r) | (x >> (32 - r))) static unsigned FUZ_rand(unsigned* src) { @@ -1208,8 +1205,8 @@ static int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, U32 const maxD U32 result = 0; U32 testNb = 0; U32 coreSeed = seed, lseed = 0; - clock_t const startClock = clock(); - clock_t const maxClockSpan = maxDurationS * CLOCKS_PER_SEC; + UTIL_time_t const startClock = UTIL_getTime(); + U64 const maxClockSpan = maxDurationS * SEC_TO_MICRO; int const cLevelLimiter = bigTests ? 3 : 2; /* allocation */ @@ -1234,7 +1231,7 @@ static int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, U32 const maxD for (testNb=1; testNb < startTest; testNb++) FUZ_rand(&coreSeed); /* main test loop */ - for ( ; (testNb <= nbTests) || (FUZ_clockSpan(startClock) < maxClockSpan); testNb++ ) { + for ( ; (testNb <= nbTests) || (UTIL_clockSpanMicro(startClock) < maxClockSpan); testNb++ ) { size_t sampleSize, maxTestSize, totalTestSize; size_t cSize, totalCSize, totalGenSize; U64 crcOrig; diff --git a/tests/paramgrill.c b/tests/paramgrill.c index 081a284e..ae14aa07 100644 --- a/tests/paramgrill.c +++ b/tests/paramgrill.c @@ -17,13 +17,14 @@ #include /* fprintf, fopen, ftello64 */ #include /* strcmp */ #include /* log */ -#include /* clock_t */ +#include #include "mem.h" #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_parameters, ZSTD_estimateCCtxSize */ #include "zstd.h" #include "datagen.h" #include "xxhash.h" +#include "util.h" /*-************************************ @@ -39,7 +40,7 @@ #define GB *(1ULL<<30) #define NBLOOPS 2 -#define TIMELOOP (2 * CLOCKS_PER_SEC) +#define TIMELOOP (2 * SEC_TO_MICRO) #define NB_LEVELS_TRACKED 30 @@ -49,8 +50,8 @@ static const size_t maxMemory = (sizeof(size_t)==4) ? (2 GB - 64 MB) : (size_t static const size_t sampleSize = 10000000; static const double g_grillDuration_s = 90000; /* about 24 hours */ -static const clock_t g_maxParamTime = 15 * CLOCKS_PER_SEC; -static const clock_t g_maxVariationTime = 60 * CLOCKS_PER_SEC; +static const U64 g_maxParamTime = 15 * SEC_TO_MICRO; +static const U64 g_maxVariationTime = 60 * SEC_TO_MICRO; static const int g_maxNbVariations = 64; @@ -88,13 +89,9 @@ void BMK_SetNbIterations(int nbLoops) * Private functions *********************************************************/ -/* works even if overflow ; max span ~ 30 mn */ -static clock_t BMK_clockSpan(clock_t cStart) { return clock() - cStart; } - /* accuracy in seconds only, span can be multiple years */ static double BMK_timeSpan(time_t tStart) { return difftime(time(NULL), tStart); } - static size_t BMK_findMaxMem(U64 requiredMem) { size_t const step = 64 MB; @@ -221,7 +218,7 @@ static size_t BMK_benchParam(BMK_result_t* resultPtr, size_t cSize = 0; double fastestC = 100000000., fastestD = 100000000.; double ratio = 0.; - clock_t const benchStart = clock(); + UTIL_time_t const benchStart = UTIL_getTime(); DISPLAY("\r%79s\r", ""); memset(¶ms, 0, sizeof(params)); @@ -229,9 +226,10 @@ static size_t BMK_benchParam(BMK_result_t* resultPtr, for (loopNb = 1; loopNb <= g_nbIterations; loopNb++) { int nbLoops; U32 blockNb; - clock_t roundStart, roundClock; + UTIL_time_t roundStart; + U64 roundClock; - { clock_t const benchTime = BMK_clockSpan(benchStart); + { U64 const benchTime = UTIL_clockSpanMicro(benchStart); if (benchTime > g_maxParamTime) break; } /* Compression */ @@ -239,10 +237,9 @@ static size_t BMK_benchParam(BMK_result_t* resultPtr, memset(compressedBuffer, 0xE5, maxCompressedSize); nbLoops = 0; - roundStart = clock(); - while (clock() == roundStart); - roundStart = clock(); - while (BMK_clockSpan(roundStart) < TIMELOOP) { + UTIL_waitForNextTick(); + roundStart = UTIL_getTime(); + while (UTIL_clockSpanMicro(roundStart) < TIMELOOP) { for (blockNb=0; blockNb", loopNb, name, (U32)srcSize); DISPLAY(" %9u (%4.3f),%7.1f MB/s", (U32)cSize, ratio, (double)srcSize / fastestC / 1000000.); @@ -269,17 +266,16 @@ static size_t BMK_benchParam(BMK_result_t* resultPtr, memset(resultBuffer, 0xD6, srcSize); nbLoops = 0; - roundStart = clock(); - while (clock() == roundStart); - roundStart = clock(); - for ( ; BMK_clockSpan(roundStart) < TIMELOOP; nbLoops++) { + UTIL_waitForNextTick(); + roundStart = UTIL_getTime(); + for ( ; UTIL_clockSpanMicro(roundStart) < TIMELOOP; nbLoops++) { for (blockNb=0; blockNb ", loopNb, name, (U32)srcSize); DISPLAY("%9u (%4.3f),%7.1f MB/s, ", (U32)cSize, ratio, (double)srcSize / fastestC / 1000000.); @@ -521,9 +517,9 @@ static void playAround(FILE* f, winnerInfo_t* winners, ZSTD_CCtx* ctx) { int nbVariations = 0; - clock_t const clockStart = clock(); + UTIL_time_t const clockStart = UTIL_getTime(); - while (BMK_clockSpan(clockStart) < g_maxVariationTime) { + while (UTIL_clockSpanMicro(clockStart) < g_maxVariationTime) { ZSTD_compressionParameters p = params; if (nbVariations++ > g_maxNbVariations) break; diff --git a/tests/zbufftest.c b/tests/zbufftest.c index ce5e5518..9b6f7bad 100644 --- a/tests/zbufftest.c +++ b/tests/zbufftest.c @@ -24,7 +24,6 @@ **************************************/ #include /* free */ #include /* fgets, sscanf */ -#include /* clock_t, clock() */ #include /* strcmp */ #include "mem.h" #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_maxCLevel */ @@ -34,6 +33,7 @@ #include "datagen.h" /* RDG_genBuffer */ #define XXH_STATIC_LINKING_ONLY #include "xxhash.h" /* XXH64_* */ +#include "util.h" /*-************************************ @@ -58,26 +58,24 @@ static const U32 prime2 = 2246822519U; #define DISPLAYLEVEL(l, ...) if (g_displayLevel>=l) { DISPLAY(__VA_ARGS__); } static U32 g_displayLevel = 2; -#define DISPLAYUPDATE(l, ...) if (g_displayLevel>=l) { \ - if ((FUZ_GetClockSpan(g_displayClock) > g_refreshRate) || (g_displayLevel>=4)) \ - { g_displayClock = clock(); DISPLAY(__VA_ARGS__); \ - if (g_displayLevel>=4) fflush(stderr); } } -static const clock_t g_refreshRate = CLOCKS_PER_SEC * 15 / 100; -static clock_t g_displayClock = 0; +static const U64 g_refreshRate = SEC_TO_MICRO / 6; +static UTIL_time_t g_displayClock = UTIL_TIME_INITIALIZER; -static clock_t g_clockTime = 0; +#define DISPLAYUPDATE(l, ...) if (g_displayLevel>=l) { \ + if ((UTIL_clockSpanMicro(g_displayClock) > g_refreshRate) || (g_displayLevel>=4)) \ + { g_displayClock = UTIL_getTime(); DISPLAY(__VA_ARGS__); \ + if (g_displayLevel>=4) fflush(stderr); } } + +static U64 g_clockTime = 0; /*-******************************************************* * Fuzzer functions *********************************************************/ +#undef MIN +#undef MAX +#define MIN(a,b) ((a)<(b)?(a):(b)) #define MAX(a,b) ((a)>(b)?(a):(b)) - -static clock_t FUZ_GetClockSpan(clock_t clockStart) -{ - return clock() - clockStart; /* works even when overflow. Max span ~ 30 mn */ -} - /*! FUZ_rand() : @return : a 27 bits random value, from a 32-bits `seed`. `seed` is also modified */ @@ -256,8 +254,6 @@ static size_t FUZ_randomLength(U32* seed, U32 maxLog) return FUZ_rLogLength(seed, logLength); } -#define MIN(a,b) ( (a) < (b) ? (a) : (b) ) - #define CHECK(cond, ...) if (cond) { DISPLAY("Error => "); DISPLAY(__VA_ARGS__); \ DISPLAY(" (seed %u, test nb %u) \n", seed, testNb); goto _output_error; } @@ -278,7 +274,7 @@ static int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compres U32 coreSeed = seed; ZBUFF_CCtx* zc; ZBUFF_DCtx* zd; - clock_t startClock = clock(); + UTIL_time_t startClock = UTIL_getTime(); /* allocations */ zc = ZBUFF_createCCtx(); @@ -308,7 +304,7 @@ static int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compres FUZ_rand(&coreSeed); /* test loop */ - for ( ; (testNb <= nbTests) || (FUZ_GetClockSpan(startClock) < g_clockTime) ; testNb++ ) { + for ( ; (testNb <= nbTests) || (UTIL_clockSpanMicro(startClock) < g_clockTime) ; testNb++ ) { U32 lseed; const BYTE* srcBuffer; const BYTE* dict; @@ -548,7 +544,7 @@ int main(int argc, const char** argv) } if (*argument=='m') g_clockTime *=60, argument++; if (*argument=='n') argument++; - g_clockTime *= CLOCKS_PER_SEC; + g_clockTime *= SEC_TO_MICRO; break; case 's': diff --git a/tests/zstreamtest.c b/tests/zstreamtest.c index b8c437a4..207b2e01 100644 --- a/tests/zstreamtest.c +++ b/tests/zstreamtest.c @@ -24,7 +24,6 @@ **************************************/ #include /* free */ #include /* fgets, sscanf */ -#include /* clock_t, clock() */ #include /* strcmp */ #include /* assert */ #include "mem.h" @@ -37,6 +36,7 @@ #define XXH_STATIC_LINKING_ONLY /* XXH64_state_t */ #include "xxhash.h" /* XXH64_* */ #include "seqgen.h" +#include "util.h" /*-************************************ @@ -62,26 +62,24 @@ static const U32 prime32 = 2654435761U; if (g_displayLevel>=4) fflush(stderr); } static U32 g_displayLevel = 2; -#define DISPLAYUPDATE(l, ...) if (g_displayLevel>=l) { \ - if ((FUZ_GetClockSpan(g_displayClock) > g_refreshRate) || (g_displayLevel>=4)) \ - { g_displayClock = clock(); DISPLAY(__VA_ARGS__); \ - if (g_displayLevel>=4) fflush(stderr); } } -static const clock_t g_refreshRate = CLOCKS_PER_SEC / 6; -static clock_t g_displayClock = 0; +static const U64 g_refreshRate = SEC_TO_MICRO / 6; +static UTIL_time_t g_displayClock = UTIL_TIME_INITIALIZER; -static clock_t g_clockTime = 0; +#define DISPLAYUPDATE(l, ...) if (g_displayLevel>=l) { \ + if ((UTIL_clockSpanMicro(g_displayClock) > g_refreshRate) || (g_displayLevel>=4)) \ + { g_displayClock = UTIL_getTime(); DISPLAY(__VA_ARGS__); \ + if (g_displayLevel>=4) fflush(stderr); } } + +static U64 g_clockTime = 0; /*-******************************************************* * Fuzzer functions *********************************************************/ +#undef MIN +#undef MAX +#define MIN(a,b) ((a)<(b)?(a):(b)) #define MAX(a,b) ((a)>(b)?(a):(b)) - -static clock_t FUZ_GetClockSpan(clock_t clockStart) -{ - return clock() - clockStart; /* works even when overflow. Max span ~ 30 mn */ -} - /*! FUZ_rand() : @return : a 27 bits random value, from a 32-bits `seed`. `seed` is also modified */ @@ -815,8 +813,6 @@ static size_t FUZ_randomLength(U32* seed, U32 maxLog) return FUZ_rLogLength(seed, logLength); } -#define MIN(a,b) ( (a) < (b) ? (a) : (b) ) - /* Return value in range minVal <= v <= maxVal */ static U32 FUZ_randomClampedLength(U32* seed, U32 minVal, U32 maxVal) { @@ -842,7 +838,7 @@ static int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compres ZSTD_CStream* zc = ZSTD_createCStream(); /* will be re-created sometimes */ ZSTD_DStream* zd = ZSTD_createDStream(); /* will be re-created sometimes */ ZSTD_DStream* const zd_noise = ZSTD_createDStream(); - clock_t const startClock = clock(); + UTIL_time_t const startClock = UTIL_getTime(); const BYTE* dict = NULL; /* can keep same dict on 2 consecutive tests */ size_t dictSize = 0; U32 oldTestLog = 0; @@ -872,7 +868,7 @@ static int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compres FUZ_rand(&coreSeed); /* test loop */ - for ( ; (testNb <= nbTests) || (FUZ_GetClockSpan(startClock) < g_clockTime) ; testNb++ ) { + for ( ; (testNb <= nbTests) || (UTIL_clockSpanMicro(startClock) < g_clockTime) ; testNb++ ) { U32 lseed; const BYTE* srcBuffer; size_t totalTestSize, totalGenSize, cSize; @@ -1092,7 +1088,7 @@ static int fuzzerTests_MT(U32 seed, U32 nbTests, unsigned startTest, double comp ZSTDMT_CCtx* zc = ZSTDMT_createCCtx(nbThreads); /* will be reset sometimes */ ZSTD_DStream* zd = ZSTD_createDStream(); /* will be reset sometimes */ ZSTD_DStream* const zd_noise = ZSTD_createDStream(); - clock_t const startClock = clock(); + UTIL_time_t const startClock = UTIL_getTime(); const BYTE* dict=NULL; /* can keep same dict on 2 consecutive tests */ size_t dictSize = 0; U32 oldTestLog = 0; @@ -1123,7 +1119,7 @@ static int fuzzerTests_MT(U32 seed, U32 nbTests, unsigned startTest, double comp FUZ_rand(&coreSeed); /* test loop */ - for ( ; (testNb <= nbTests) || (FUZ_GetClockSpan(startClock) < g_clockTime) ; testNb++ ) { + for ( ; (testNb <= nbTests) || (UTIL_clockSpanMicro(startClock) < g_clockTime) ; testNb++ ) { U32 lseed; const BYTE* srcBuffer; size_t totalTestSize, totalGenSize, cSize; @@ -1364,7 +1360,7 @@ static int fuzzerTests_newAPI(U32 seed, U32 nbTests, unsigned startTest, double ZSTD_CCtx* zc = ZSTD_createCCtx(); /* will be reset sometimes */ ZSTD_DStream* zd = ZSTD_createDStream(); /* will be reset sometimes */ ZSTD_DStream* const zd_noise = ZSTD_createDStream(); - clock_t const startClock = clock(); + UTIL_time_t const startClock = UTIL_getTime(); const BYTE* dict = NULL; /* can keep same dict on 2 consecutive tests */ size_t dictSize = 0; U32 oldTestLog = 0; @@ -1397,7 +1393,7 @@ static int fuzzerTests_newAPI(U32 seed, U32 nbTests, unsigned startTest, double FUZ_rand(&coreSeed); /* test loop */ - for ( ; (testNb <= nbTests) || (FUZ_GetClockSpan(startClock) < g_clockTime) ; testNb++ ) { + for ( ; (testNb <= nbTests) || (UTIL_clockSpanMicro(startClock) < g_clockTime) ; testNb++ ) { U32 lseed; const BYTE* srcBuffer; size_t totalTestSize, totalGenSize, cSize; @@ -1772,7 +1768,7 @@ int main(int argc, const char** argv) g_clockTime *=60, argument++; if (*argument=='n') argument++; /* -T1mn == -T60 */ } else if (*argument=='s') argument++; /* -T10s == -T10 */ - g_clockTime *= CLOCKS_PER_SEC; + g_clockTime *= SEC_TO_MICRO; break; case 's': /* manually select seed */