]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fixed benchmark autogen
authorYann Collet <yann.collet.73@gmail.com>
Tue, 1 Dec 2015 00:31:17 +0000 (01:31 +0100)
committerYann Collet <yann.collet.73@gmail.com>
Tue, 1 Dec 2015 00:31:17 +0000 (01:31 +0100)
programs/bench.c
programs/datagen.c
programs/datagen.h
programs/zstdcli.c

index fa7ec5579b71b0da018f1a1c737a5a25d86f34ce..c48112f1d5be21ae0d56dc62543d535cb2174aec 100644 (file)
 
 /* Use ftime() if gettimeofday() is not available */
 #if defined(BMK_LEGACY_TIMER)
-#  include <sys/timeb.h>   /* timeb, ftime */
+#  include <sys/timeb.h>  /* timeb, ftime */
 #else
-#  include <sys/time.h>    /* gettimeofday */
+#  include <sys/time.h>   /* gettimeofday */
 #endif
 
 #include "mem.h"
 #include "zstd.h"
 #include "xxhash.h"
+#include "datagen.h"      /* RDG_genBuffer */
 
 
 /* *************************************
 #define MB *(1 <<20)
 #define GB *(1U<<30)
 
-static const size_t maxMemory = sizeof(size_t)==4  ?  (2 GB - 64 MB) : (size_t)(1ULL << ((sizeof(size_t)*8)-31));
+static const size_t maxMemory = (sizeof(size_t)==4)  ?  (2 GB - 64 MB) : (size_t)(1ULL << ((sizeof(size_t)*8)-31));
 #define DEFAULT_CHUNKSIZE   (4 MB)
 
 static U32 g_compressibilityDefault = 50;
-static U32 prime1 = 2654435761U;
-static U32 prime2 = 2246822519U;
 
 
 /* *************************************
@@ -158,62 +157,6 @@ static int BMK_GetMilliSpan( int nTimeStart )
 }
 
 
-/* ********************************************************
-*  Data generator
-**********************************************************/
-/* will hopefully be converted into ROL instruction by compiler */
-static U32 BMK_rotl32(unsigned val32, unsigned nbBits) { return((val32 << nbBits) | (val32 >> (32 - nbBits))); }
-
-static U32 BMK_rand(U32* src)
-{
-    U32 rand32 = *src;
-    rand32 *= prime1;
-    rand32 += prime2;
-    rand32 = BMK_rotl32(rand32, 13);
-    *src = rand32;
-    return rand32 >> 9;
-}
-
-#define BMK_RAND15BITS  ( BMK_rand(&seed) & 0x7FFF)
-#define BMK_RANDLENGTH  ((BMK_rand(&seed) & 3) ? (BMK_rand(&seed) % 15) : (BMK_rand(&seed) % 510) + 15)
-#define BMK_RANDCHAR    (BYTE)((BMK_rand(&seed) & 63) + '0')
-static void BMK_datagen(void* buffer, size_t bufferSize, double proba, U32 seed)
-{
-    BYTE* BBuffer = (BYTE*)buffer;
-    unsigned pos = 0;
-    U32 P32 = (U32)(32768 * proba);
-
-    /* First Byte */
-    BBuffer[pos++] = BMK_RANDCHAR;
-
-    while (pos < bufferSize)
-    {
-        /* Select : Literal (noise) or copy (within 64K) */
-        if (BMK_RAND15BITS < P32)
-        {
-            /* Match */
-            size_t match, end;
-            unsigned length = BMK_RANDLENGTH + 4;
-            unsigned offset = BMK_RAND15BITS + 1;
-            if (offset > pos) offset = pos;
-            match = pos - offset;
-            end = pos + length;
-            if (end > bufferSize) end = bufferSize;
-            while (pos < end) BBuffer[pos++] = BBuffer[match++];
-        }
-        else
-        {
-            /* Literal */
-            size_t end;
-            unsigned length = BMK_RANDLENGTH;
-            end = pos + length;
-            if (end > bufferSize) end = bufferSize;
-            while (pos < end) BBuffer[pos++] = BMK_RANDCHAR;
-        }
-    }
-}
-
-
 /* ********************************************************
 *  Bench functions
 **********************************************************/
@@ -283,7 +226,7 @@ static int BMK_benchMem(void* srcBuffer, size_t srcSize, const char* fileName, i
     }
 
     /* warmimg up memory */
-    BMK_datagen(compressedBuffer, maxCompressedSize, 0.10, 1);
+    RDG_genBuffer(compressedBuffer, maxCompressedSize, 0.10, 0.50, 1);
 
     /* Bench */
     {
@@ -481,7 +424,7 @@ static int BMK_syntheticTest(int cLevel, double compressibility)
     }
 
     /* Fill input buffer */
-    BMK_datagen(srcBuffer, benchedSize, compressibility, 0);
+    RDG_genBuffer(srcBuffer, benchedSize, compressibility, 0.0, 0);
 
     /* Bench */
 #ifdef _MSC_VER
index f5aa9c5dae8a7dc1c38a17f58f9fc18d6e6b81c2..2bb342613578164eb2c5dfe8a5292cfe974da2d0 100644 (file)
@@ -173,6 +173,7 @@ void RDG_genBlock(void* buffer, size_t buffSize, size_t prefixSize, double match
             U32 repeatOffset = (RDG_rand(seed) & 15) == 2;
             if (repeatOffset) offset = prevOffset;
             if (offset > pos) offset = (U32)pos;
+            prevOffset = offset;
             match = pos - offset;
             d = pos + length;
             if (d > buffSize) d = buffSize;
index 03b06cae59bd592eafb748c115eb7ff860c58fbe..de4a0740c641c5c3957efa73a4601e3077ccdbf4 100644 (file)
@@ -28,7 +28,7 @@
 
 void RDG_genStdout(unsigned long long size, double matchProba, double litProba, unsigned seed);
 void RDG_genBuffer(void* buffer, size_t size, double matchProba, double litProba, unsigned seed);
-/* RDG_genBuffer
+/*!RDG_genBuffer
    Generate 'size' bytes of compressible data into 'buffer'.
    Compressibility can be controlled using 'matchProba', which is floating point value between 0 and 1.
    'LitProba' is optional, it affect variability of individual bytes. If litProba==0.0, default value will be used.
index 418fec70bd7e292711432971c6b4b159c671e59e..235b56cf3b6597e41326724f84910b817e91ab6e 100644 (file)
@@ -182,19 +182,13 @@ int main(int argCount, const char** argv)
 
     displayOut = stderr;
     /* Pick out basename component. Don't rely on stdlib because of conflicting behavior. */
-    for (i = (int)strlen(programName); i > 0; i--)
-    {
-        if (programName[i] == '/') { i++; break; }
-    }
+    for (i = (int)strlen(programName); i > 0; i--) { if (programName[i] == '/') { i++; break; } }
     programName += i;
 
-    /* zstdcat preset behavior */
+    /* preset behaviors */
+    if (!strcmp(programName, ZSTD_UNZSTD)) decode=1;
     if (!strcmp(programName, ZSTD_CAT)) { decode=1; forceStdout=1; displayLevel=1; outFileName=stdoutmark; }
 
-    /* unzstd preset behavior */
-    if (!strcmp(programName, ZSTD_UNZSTD))
-        decode=1;
-
     /* command switches */
     for(i=1; i<argCount; i++)
     {
@@ -325,15 +319,15 @@ int main(int argCount, const char** argv)
     /* Welcome message (if verbose) */
     DISPLAYLEVEL(3, WELCOME_MESSAGE);
 
+    /* Check if benchmark is selected */
+    if (bench) { BMK_benchFiles(argv+fileNameStart, nbFiles, cLevel*rangeBench); goto _end; }
+
     /* No input filename ==> use stdin */
     if(!inFileName) { inFileName=stdinmark; }
 
     /* Check if input defined as console; trigger an error in this case */
     if (!strcmp(inFileName, stdinmark) && IS_CONSOLE(stdin) ) return badusage(programName);
 
-    /* Check if benchmark is selected */
-    if (bench) { BMK_benchFiles(argv+fileNameStart, nbFiles, cLevel*rangeBench); goto _end; }
-
     /* No output filename ==> try to select one automatically (when possible) */
     while (!outFileName)
     {