From e7e5a8cef7b6e1ac3bcbb7a25a4401072fd02a36 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Thu, 29 Jun 2017 18:56:24 -0700 Subject: [PATCH] made fullbench compatible with multi-threading fullbench 61/62 measure speed of ZSTD_compress_generic with 2 threads --- tests/Makefile | 10 ++--- tests/fullbench.c | 96 +++++++++++++++++++++++++++++++++-------------- 2 files changed, 72 insertions(+), 34 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index 5c240800..0b8deec2 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -94,11 +94,11 @@ zstd-nolegacy: gzstd: $(MAKE) -C $(PRGDIR) $@ -fullbench : $(ZSTD_FILES) $(PRGDIR)/datagen.c fullbench.c - $(CC) $(FLAGS) $^ -o $@$(EXT) - -fullbench32 : $(ZSTD_FILES) $(PRGDIR)/datagen.c fullbench.c - $(CC) -m32 $(FLAGS) $^ -o $@$(EXT) +fullbench32: CPPFLAGS += -m32 +fullbench fullbench32 : CPPFLAGS += $(MULTITHREAD_CPP) +fullbench fullbench32 : LDFLAGS += $(MULTITHREAD_LD) +fullbench fullbench32 : $(ZSTD_FILES) $(PRGDIR)/datagen.c fullbench.c + $(CC) $(FLAGS) $^ -o $@$(EXT) fullbench-lib: $(PRGDIR)/datagen.c fullbench.c $(MAKE) -C $(ZSTDDIR) libzstd.a diff --git a/tests/fullbench.c b/tests/fullbench.c index 1c1807a5..176e5a62 100644 --- a/tests/fullbench.c +++ b/tests/fullbench.c @@ -14,9 +14,8 @@ #include "util.h" /* Compiler options, UTIL_GetFileSize */ #include /* malloc */ #include /* fprintf, fopen, ftello64 */ -#include /* clock_t, clock, CLOCKS_PER_SEC */ -#include "mem.h" +#include "mem.h" /* U32 */ #ifndef ZSTD_DLL_IMPORT #include "zstd_internal.h" /* ZSTD_blockHeaderSize, blockType_e, KB, MB */ #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_compressBegin, ZSTD_compressContinue, etc. */ @@ -26,7 +25,8 @@ #define GB *(1U<<30) typedef enum { bt_raw, bt_rle, bt_compressed, bt_reserved } blockType_e; #endif -#include "zstd.h" /* ZSTD_VERSION_STRING */ +#include "zstd.h" /* ZSTD_versionString */ +#include "util.h" /* time functions */ #include "datagen.h" @@ -35,7 +35,7 @@ **************************************/ #define PROGRAM_DESCRIPTION "Zstandard speed analyzer" #define AUTHOR "Yann Collet" -#define WELCOME_MESSAGE "*** %s %s %i-bits, by %s (%s) ***\n", PROGRAM_DESCRIPTION, ZSTD_VERSION_STRING, (int)(sizeof(void*)*8), AUTHOR, __DATE__ +#define WELCOME_MESSAGE "*** %s %s %i-bits, by %s (%s) ***\n", PROGRAM_DESCRIPTION, ZSTD_versionString(), (int)(sizeof(void*)*8), AUTHOR, __DATE__ #define NBLOOPS 6 #define TIMELOOP_S 2 @@ -69,12 +69,6 @@ static void BMK_SetNbIterations(U32 nbLoops) /*_******************************************************* * Private functions *********************************************************/ -static clock_t BMK_clockSpan( clock_t clockStart ) -{ - return clock() - clockStart; /* works even if overflow, span limited to <= ~30mn */ -} - - static size_t BMK_findMaxMem(U64 requiredMem) { size_t const step = 64 MB; @@ -186,6 +180,41 @@ static size_t local_ZSTD_compress_generic_continue(void* dst, size_t dstCapacity return buffOut.pos; } +static size_t local_ZSTD_compress_generic_T2_end(void* dst, size_t dstCapacity, void* buff2, const void* src, size_t srcSize) +{ + ZSTD_outBuffer buffOut; + ZSTD_inBuffer buffIn; + (void)buff2; + ZSTD_CCtx_setParameter(g_cstream, ZSTD_p_compressionLevel, 1); + ZSTD_CCtx_setParameter(g_cstream, ZSTD_p_nbThreads, 2); + buffOut.dst = dst; + buffOut.size = dstCapacity; + buffOut.pos = 0; + buffIn.src = src; + buffIn.size = srcSize; + buffIn.pos = 0; + while (ZSTD_compress_generic(g_cstream, &buffOut, &buffIn, ZSTD_e_end)) {} + return buffOut.pos; +} + +static size_t local_ZSTD_compress_generic_T2_continue(void* dst, size_t dstCapacity, void* buff2, const void* src, size_t srcSize) +{ + ZSTD_outBuffer buffOut; + ZSTD_inBuffer buffIn; + (void)buff2; + ZSTD_CCtx_setParameter(g_cstream, ZSTD_p_compressionLevel, 1); + ZSTD_CCtx_setParameter(g_cstream, ZSTD_p_nbThreads, 2); + buffOut.dst = dst; + buffOut.size = dstCapacity; + buffOut.pos = 0; + buffIn.src = src; + buffIn.size = srcSize; + buffIn.pos = 0; + ZSTD_compress_generic(g_cstream, &buffOut, &buffIn, ZSTD_e_continue); + while(ZSTD_compress_generic(g_cstream, &buffOut, &buffIn, ZSTD_e_end)) {} + return buffOut.pos; +} + static ZSTD_DStream* g_dstream= NULL; static size_t local_ZSTD_decompressStream(void* dst, size_t dstCapacity, void* buff2, const void* src, size_t srcSize) { @@ -269,39 +298,45 @@ static size_t benchMem(const void* src, size_t srcSize, U32 benchNb) switch(benchNb) { case 1: - benchFunction = local_ZSTD_compress; benchName = "ZSTD_compress(1)"; + benchFunction = local_ZSTD_compress; benchName = "compress(1)"; break; case 2: - benchFunction = local_ZSTD_decompress; benchName = "ZSTD_decompress"; + benchFunction = local_ZSTD_decompress; benchName = "decompress"; break; #ifndef ZSTD_DLL_IMPORT case 11: - benchFunction = local_ZSTD_compressContinue; benchName = "ZSTD_compressContinue(1)"; + benchFunction = local_ZSTD_compressContinue; benchName = "compressContinue(1)"; break; case 12: - benchFunction = local_ZSTD_compressContinue_extDict; benchName = "ZSTD_compressContinue_extDict"; + benchFunction = local_ZSTD_compressContinue_extDict; benchName = "compressContinue_extDict"; break; case 13: - benchFunction = local_ZSTD_decompressContinue; benchName = "ZSTD_decompressContinue"; + benchFunction = local_ZSTD_decompressContinue; benchName = "decompressContinue"; break; case 31: - benchFunction = local_ZSTD_decodeLiteralsBlock; benchName = "ZSTD_decodeLiteralsBlock"; + benchFunction = local_ZSTD_decodeLiteralsBlock; benchName = "decodeLiteralsBlock"; break; case 32: - benchFunction = local_ZSTD_decodeSeqHeaders; benchName = "ZSTD_decodeSeqHeaders"; + benchFunction = local_ZSTD_decodeSeqHeaders; benchName = "decodeSeqHeaders"; break; #endif case 41: - benchFunction = local_ZSTD_compressStream; benchName = "ZSTD_compressStream(1)"; + benchFunction = local_ZSTD_compressStream; benchName = "compressStream(1)"; break; case 42: - benchFunction = local_ZSTD_decompressStream; benchName = "ZSTD_decompressStream"; + benchFunction = local_ZSTD_decompressStream; benchName = "decompressStream"; break; case 51: - benchFunction = local_ZSTD_compress_generic_continue; benchName = "ZSTD_compress_generic, continue"; + benchFunction = local_ZSTD_compress_generic_continue; benchName = "compress_generic, continue"; break; case 52: - benchFunction = local_ZSTD_compress_generic_end; benchName = "ZSTD_compress_generic, end"; + benchFunction = local_ZSTD_compress_generic_end; benchName = "compress_generic, end"; + break; + case 61: + benchFunction = local_ZSTD_compress_generic_T2_continue; benchName = "compress_generic, -T2, continue"; + break; + case 62: + benchFunction = local_ZSTD_compress_generic_T2_end; benchName = "compress_generic, -T2, end"; break; default : return 0; @@ -389,22 +424,25 @@ static size_t benchMem(const void* src, size_t srcSize, U32 benchNb) { size_t i; for (i=0; i %s !! \n", benchName, ZSTD_getErrorName(benchResult)); exit(1); } } - { clock_t const clockTotal = BMK_clockSpan(clockStart); - double const averageTime = (double)clockTotal / CLOCKS_PER_SEC / nbRounds; + { U64 const clockSpanMicro = UTIL_clockSpanMicro(clockStart, ticksPerSecond); + double const averageTime = (double)clockSpanMicro / TIME_SEC_MICROSEC / nbRounds; if (averageTime < bestTime) bestTime = averageTime; DISPLAY("%2i- %-30.30s : %7.1f MB/s (%9u)\r", loopNb, benchName, (double)srcSize / (1 MB) / bestTime, (U32)benchResult); } } }