/* 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;
/* *************************************
}
-/* ********************************************************
-* 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
**********************************************************/
}
/* warmimg up memory */
- BMK_datagen(compressedBuffer, maxCompressedSize, 0.10, 1);
+ RDG_genBuffer(compressedBuffer, maxCompressedSize, 0.10, 0.50, 1);
/* Bench */
{
}
/* Fill input buffer */
- BMK_datagen(srcBuffer, benchedSize, compressibility, 0);
+ RDG_genBuffer(srcBuffer, benchedSize, compressibility, 0.0, 0);
/* Bench */
#ifdef _MSC_VER
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.
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++)
{
/* 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)
{