From 1c00dc3e2467cfb7316fb6ba1d2223ca45b98792 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 21 Oct 2015 08:22:25 +0100 Subject: [PATCH] Added block size to bench --- programs/Makefile | 2 +- programs/bench.c | 87 +++++++++++++++++++++++++++++++++++----------- programs/bench.h | 1 + programs/fuzzer.c | 2 -- programs/zstdcli.c | 24 ++++++++++--- 5 files changed, 87 insertions(+), 29 deletions(-) diff --git a/programs/Makefile b/programs/Makefile index bbdc07e9b..bf7768c7a 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -35,7 +35,7 @@ VERSION?= v0.2.0 DESTDIR?= PREFIX ?= /usr/local CPPFLAGS= -I../lib -I../lib/legacy -DZSTD_VERSION=\"$(VERSION)\" -DZSTD_LEGACY_SUPPORT=1 -CFLAGS ?= -O3 +CFLAGS ?= -O3 # -falign-loops=32 # not always positive CFLAGS += -std=c99 -Wall -Wextra -Wundef -Wshadow -Wcast-qual -Wcast-align -Wstrict-prototypes FLAGS = $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(MOREFLAGS) diff --git a/programs/bench.c b/programs/bench.c index 5fdf01093..53ff5e9e9 100644 --- a/programs/bench.c +++ b/programs/bench.c @@ -118,6 +118,7 @@ static U32 prime2 = 2246822519U; * Benchmark Parameters **************************************/ static int nbIterations = NBLOOPS; +static size_t g_blockSize = 0; void BMK_SetNbIterations(int nbLoops) { @@ -125,6 +126,12 @@ void BMK_SetNbIterations(int nbLoops) DISPLAY("- %i iterations -\n", nbIterations); } +void BMK_SetBlockSize(size_t blockSize) +{ + g_blockSize = blockSize; + DISPLAY("using blocks of size %u KB \n", (U32)(blockSize>>10)); +} + /********************************************************* * Private functions @@ -230,31 +237,70 @@ static void BMK_datagen(void* buffer, size_t bufferSize, double proba, U32 seed) /********************************************************* * Bench functions *********************************************************/ - -static int BMK_benchMem(void* srcBuffer, size_t srcSize, char* fileName, int cLevel) +typedef struct { - size_t maxCompressedSize = ZSTD_compressBound(srcSize); - void* compressedBuffer = malloc(maxCompressedSize); - void* resultBuffer = malloc(srcSize); + char* srcPtr; + size_t srcSize; + char* cPtr; + size_t cRoom; + size_t cSize; + char* resPtr; + size_t resSize; +} blockParam_t; + + +#define MIN(a,b) (a\r", loopNb, fileName, (U32)srcSize); @@ -280,11 +327,16 @@ static int BMK_benchMem(void* srcBuffer, size_t srcSize, char* fileName, int cLe milliTime = BMK_GetMilliStart(); while (BMK_GetMilliSpan(milliTime) < TIMELOOP) { - cSize = ZSTD_compress(compressedBuffer, maxCompressedSize, srcBuffer, srcSize); + for (blockNb=0; blockNb %9i (%5.2f%%),%7.1f MB/s\r", loopNb, fileName, (int)srcSize, (int)cSize, ratio, (double)srcSize / fastestC / 1000.); @@ -299,12 +351,9 @@ static int BMK_benchMem(void* srcBuffer, size_t srcSize, char* fileName, int cLe milliTime = BMK_GetMilliStart(); for ( ; BMK_GetMilliSpan(milliTime) < TIMELOOP; nbLoops++) { - size_t result = ZSTD_decompress(resultBuffer, srcSize, compressedBuffer, cSize); - if (ZSTD_isError(result)) - { - DISPLAY("\n!!! Decompression error !!! %s !\n", ZSTD_getErrorName(result)); - break; - } + for (blockNb=0; blockNb inFileSize) benchedSize = (size_t)inFileSize; if (benchedSize < inFileSize) DISPLAY("Not enough memory for '%s' full size; testing %i MB only...\n", inFileName, (int)(benchedSize >> 20)); - - // Alloc srcBuffer = malloc(benchedSize); - if (!srcBuffer) { DISPLAY("\nError: not enough memory!\n"); - free(srcBuffer); fclose(inFile); return 12; } - // Fill input buffer + /* Fill input buffer */ DISPLAY("Loading %s... \r", inFileName); readSize = fread(srcBuffer, 1, benchedSize, inFile); fclose(inFile); diff --git a/programs/bench.h b/programs/bench.h index 664c034e2..08f8a3639 100644 --- a/programs/bench.h +++ b/programs/bench.h @@ -30,5 +30,6 @@ int BMK_benchFiles(char** fileNamesTable, unsigned nbFiles, unsigned cLevel); /* Set Parameters */ void BMK_SetNbIterations(int nbLoops); +void BMK_SetBlockSize(size_t blockSize); diff --git a/programs/fuzzer.c b/programs/fuzzer.c index b3294e713..632a61ab6 100644 --- a/programs/fuzzer.c +++ b/programs/fuzzer.c @@ -238,8 +238,6 @@ static int basicUnitTests(U32 seed, double compressibility) DISPLAYLEVEL(4, "OK \n"); } - - _end: free(CNBuffer); free(compressedBuffer); diff --git a/programs/zstdcli.c b/programs/zstdcli.c index e16b0ecde..790097671 100644 --- a/programs/zstdcli.c +++ b/programs/zstdcli.c @@ -138,6 +138,7 @@ static int usage_advanced(const char* programName) //DISPLAY( " -t : test compressed file integrity\n"); DISPLAY( "Benchmark arguments :\n"); DISPLAY( " -b : benchmark file(s)\n"); + DISPLAY( " -B# : cut file into independent blocks of size # (default : no block)\n"); DISPLAY( " -i# : iteration loops [1-9](default : 3)\n"); return 0; } @@ -175,7 +176,7 @@ int main(int argc, char** argv) char extension[] = ZSTD_EXTENSION; displayOut = stderr; - /* Pick out basename component. Don't rely on stdlib because of conflicting behaviour. */ + /* 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; } @@ -223,13 +224,13 @@ int main(int argc, char** argv) case 'H': case 'h': displayOut=stdout; return usage_advanced(programName); - // Compression (default) + /* Compression (default) */ //case 'z': forceCompress = 1; break; - // Decoding + /* Decoding */ case 'd': decode=1; argument++; break; - // Force stdout, even if stdout==console + /* Force stdout, even if stdout==console */ case 'c': forceStdout=1; outFileName=stdoutmark; displayLevel=1; argument++; break; // Test @@ -261,7 +262,20 @@ int main(int argc, char** argv) } break; - /* Pause at the end (hidden option) */ + /* cut input into blocks (benchmark only) */ + case 'B': + { + size_t bSize = 0; + argument++; + while ((*argument >='0') && (*argument <='9')) + bSize *= 10, bSize += *argument++ - '0'; + if (*argument=='K') bSize<<=10, argument++; /* allows using KB notation */ + if (*argument=='M') bSize<<=20, argument++; + if (*argument=='B') argument++; + BMK_SetBlockSize(bSize); + } + break; + /* Pause at the end (hidden option) */ case 'p': main_pause=1; argument++; break; /* unknown command */