summaryrefslogtreecommitdiffstats
path: root/programs/bench.c
diff options
context:
space:
mode:
authorYann Collet <cyan@fb.com>2022-07-29 13:24:50 (GMT)
committerYann Collet <cyan@fb.com>2022-07-29 13:24:50 (GMT)
commitcd96e3e7a504311cd229cf536ede86e5febec9a7 (patch)
treeb392d27fe4cb894db86d2c34b8c9be2f36e475ee /programs/bench.c
parentdf4bb410e31b913328687bc8b04a3f39f79efc8d (diff)
downloadlz4-cd96e3e7a504311cd229cf536ede86e5febec9a7.zip
lz4-cd96e3e7a504311cd229cf536ede86e5febec9a7.tar.gz
lz4-cd96e3e7a504311cd229cf536ede86e5febec9a7.tar.bz2
minor refactor
to prepare bench.c for multiple decoding functions.
Diffstat (limited to 'programs/bench.c')
-rw-r--r--programs/bench.c245
1 files changed, 123 insertions, 122 deletions
diff --git a/programs/bench.c b/programs/bench.c
index 85bf87a..633433f 100644
--- a/programs/bench.c
+++ b/programs/bench.c
@@ -54,7 +54,91 @@
/* *************************************
-* Compression parameters and functions
+* Constants
+***************************************/
+#ifndef LZ4_GIT_COMMIT_STRING
+# define LZ4_GIT_COMMIT_STRING ""
+#else
+# define LZ4_GIT_COMMIT_STRING LZ4_EXPAND_AND_QUOTE(LZ4_GIT_COMMIT)
+#endif
+
+#define NBSECONDS 3
+#define TIMELOOP_MICROSEC 1*1000000ULL /* 1 second */
+#define TIMELOOP_NANOSEC 1*1000000000ULL /* 1 second */
+#define ACTIVEPERIOD_MICROSEC 70*1000000ULL /* 70 seconds */
+#define COOLPERIOD_SEC 10
+#define DECOMP_MULT 1 /* test decompression DECOMP_MULT times longer than compression */
+
+#define KB *(1 <<10)
+#define MB *(1 <<20)
+#define GB *(1U<<30)
+
+#define LZ4_MAX_DICT_SIZE (64 KB)
+
+static const size_t maxMemory = (sizeof(size_t)==4) ? (2 GB - 64 MB) : (size_t)(1ULL << ((sizeof(size_t)*8)-31));
+
+static U32 g_compressibilityDefault = 50;
+
+
+/* *************************************
+* console display
+***************************************/
+#define DISPLAY(...) fprintf(stderr, __VA_ARGS__)
+#define DISPLAYLEVEL(l, ...) if (g_displayLevel>=l) { DISPLAY(__VA_ARGS__); }
+static U32 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(stdout); } }
+static const clock_t refreshRate = CLOCKS_PER_SEC * 15 / 100;
+static clock_t g_time = 0;
+
+
+/* *************************************
+* DEBUG and error conditions
+***************************************/
+#ifndef DEBUG
+# define DEBUG 0
+#endif
+#define DEBUGOUTPUT(...) if (DEBUG) DISPLAY(__VA_ARGS__);
+#define END_PROCESS(error, ...) \
+{ \
+ DEBUGOUTPUT("Error defined at %s, line %i : \n", __FILE__, __LINE__); \
+ DISPLAYLEVEL(1, "Error %i : ", error); \
+ DISPLAYLEVEL(1, __VA_ARGS__); \
+ DISPLAYLEVEL(1, "\n"); \
+ exit(error); \
+}
+
+#define LZ4_isError(errcode) (errcode==0)
+
+
+/* *************************************
+* Benchmark Parameters
+***************************************/
+static U32 g_nbSeconds = NBSECONDS;
+static size_t g_blockSize = 0;
+int g_additionalParam = 0;
+int g_benchSeparately = 0;
+
+void BMK_setNotificationLevel(unsigned level) { g_displayLevel=level; }
+
+void BMK_setAdditionalParam(int additionalParam) { g_additionalParam=additionalParam; }
+
+void BMK_setNbSeconds(unsigned nbSeconds)
+{
+ g_nbSeconds = nbSeconds;
+ DISPLAYLEVEL(3, "- test >= %u seconds per compression / decompression -\n", g_nbSeconds);
+}
+
+void BMK_setBlockSize(size_t blockSize) { g_blockSize = blockSize; }
+
+void BMK_setBenchSeparately(int separate) { g_benchSeparately = (separate!=0); }
+
+
+/* *************************************
+ * Compression state management
***************************************/
struct compressionParameters
@@ -79,8 +163,8 @@ struct compressionParameters
const struct compressionParameters* pThis);
};
-static void LZ4_compressInitNoStream(
- struct compressionParameters* pThis)
+static void
+LZ4_compressInitNoStream(struct compressionParameters* pThis)
{
pThis->LZ4_stream = NULL;
pThis->LZ4_dictStream = NULL;
@@ -88,8 +172,8 @@ static void LZ4_compressInitNoStream(
pThis->LZ4_dictStreamHC = NULL;
}
-static void LZ4_compressInitStream(
- struct compressionParameters* pThis)
+static void
+LZ4_compressInitStream(struct compressionParameters* pThis)
{
pThis->LZ4_stream = LZ4_createStream();
pThis->LZ4_dictStream = LZ4_createStream();
@@ -98,8 +182,8 @@ static void LZ4_compressInitStream(
LZ4_loadDict(pThis->LZ4_dictStream, pThis->dictBuf, pThis->dictSize);
}
-static void LZ4_compressInitStreamHC(
- struct compressionParameters* pThis)
+static void
+LZ4_compressInitStreamHC(struct compressionParameters* pThis)
{
pThis->LZ4_stream = NULL;
pThis->LZ4_dictStream = NULL;
@@ -108,83 +192,84 @@ static void LZ4_compressInitStreamHC(
LZ4_loadDictHC(pThis->LZ4_dictStreamHC, pThis->dictBuf, pThis->dictSize);
}
-static void LZ4_compressResetNoStream(
- const struct compressionParameters* pThis)
+static void
+LZ4_compressResetNoStream(const struct compressionParameters* pThis)
{
(void)pThis;
}
-static void LZ4_compressResetStream(
- const struct compressionParameters* pThis)
+static void
+LZ4_compressResetStream(const struct compressionParameters* pThis)
{
LZ4_resetStream_fast(pThis->LZ4_stream);
LZ4_attach_dictionary(pThis->LZ4_stream, pThis->LZ4_dictStream);
}
-static void LZ4_compressResetStreamHC(
- const struct compressionParameters* pThis)
+static void
+LZ4_compressResetStreamHC(const struct compressionParameters* pThis)
{
LZ4_resetStreamHC_fast(pThis->LZ4_streamHC, pThis->cLevel);
LZ4_attach_HC_dictionary(pThis->LZ4_streamHC, pThis->LZ4_dictStreamHC);
}
-static int LZ4_compressBlockNoStream(
- const struct compressionParameters* pThis,
- const char* src, char* dst,
- int srcSize, int dstSize)
+static int
+LZ4_compressBlockNoStream(const struct compressionParameters* pThis,
+ const char* src, char* dst,
+ int srcSize, int dstSize)
{
int const acceleration = (pThis->cLevel < 0) ? -pThis->cLevel + 1 : 1;
return LZ4_compress_fast(src, dst, srcSize, dstSize, acceleration);
}
-static int LZ4_compressBlockNoStreamHC(
- const struct compressionParameters* pThis,
- const char* src, char* dst,
- int srcSize, int dstSize)
+static int
+LZ4_compressBlockNoStreamHC(const struct compressionParameters* pThis,
+ const char* src, char* dst,
+ int srcSize, int dstSize)
{
return LZ4_compress_HC(src, dst, srcSize, dstSize, pThis->cLevel);
}
-static int LZ4_compressBlockStream(
- const struct compressionParameters* pThis,
- const char* src, char* dst,
- int srcSize, int dstSize)
+static int
+LZ4_compressBlockStream(const struct compressionParameters* pThis,
+ const char* src, char* dst,
+ int srcSize, int dstSize)
{
int const acceleration = (pThis->cLevel < 0) ? -pThis->cLevel + 1 : 1;
return LZ4_compress_fast_continue(pThis->LZ4_stream, src, dst, srcSize, dstSize, acceleration);
}
-static int LZ4_compressBlockStreamHC(
- const struct compressionParameters* pThis,
- const char* src, char* dst,
- int srcSize, int dstSize)
+static int
+LZ4_compressBlockStreamHC(const struct compressionParameters* pThis,
+ const char* src, char* dst,
+ int srcSize, int dstSize)
{
return LZ4_compress_HC_continue(pThis->LZ4_streamHC, src, dst, srcSize, dstSize);
}
-static void LZ4_compressCleanupNoStream(
- const struct compressionParameters* pThis)
+static void
+LZ4_compressCleanupNoStream(const struct compressionParameters* pThis)
{
(void)pThis;
}
-static void LZ4_compressCleanupStream(
- const struct compressionParameters* pThis)
+static void
+LZ4_compressCleanupStream(const struct compressionParameters* pThis)
{
LZ4_freeStream(pThis->LZ4_stream);
LZ4_freeStream(pThis->LZ4_dictStream);
}
-static void LZ4_compressCleanupStreamHC(
- const struct compressionParameters* pThis)
+static void
+LZ4_compressCleanupStreamHC(const struct compressionParameters* pThis)
{
LZ4_freeStreamHC(pThis->LZ4_streamHC);
LZ4_freeStreamHC(pThis->LZ4_dictStreamHC);
}
-static void LZ4_buildCompressionParameters(
- struct compressionParameters* pParams,
- int cLevel, const char* dictBuf, int dictSize)
+static void
+LZ4_buildCompressionParameters(struct compressionParameters* pParams,
+ int cLevel,
+ const char* dictBuf, int dictSize)
{
pParams->cLevel = cLevel;
pParams->dictBuf = dictBuf;
@@ -215,90 +300,6 @@ static void LZ4_buildCompressionParameters(
}
}
-#define LZ4_isError(errcode) (errcode==0)
-
-
-/* *************************************
-* Constants
-***************************************/
-#ifndef LZ4_GIT_COMMIT_STRING
-# define LZ4_GIT_COMMIT_STRING ""
-#else
-# define LZ4_GIT_COMMIT_STRING LZ4_EXPAND_AND_QUOTE(LZ4_GIT_COMMIT)
-#endif
-
-#define NBSECONDS 3
-#define TIMELOOP_MICROSEC 1*1000000ULL /* 1 second */
-#define TIMELOOP_NANOSEC 1*1000000000ULL /* 1 second */
-#define ACTIVEPERIOD_MICROSEC 70*1000000ULL /* 70 seconds */
-#define COOLPERIOD_SEC 10
-#define DECOMP_MULT 1 /* test decompression DECOMP_MULT times longer than compression */
-
-#define KB *(1 <<10)
-#define MB *(1 <<20)
-#define GB *(1U<<30)
-
-#define LZ4_MAX_DICT_SIZE (64 KB)
-
-static const size_t maxMemory = (sizeof(size_t)==4) ? (2 GB - 64 MB) : (size_t)(1ULL << ((sizeof(size_t)*8)-31));
-
-static U32 g_compressibilityDefault = 50;
-
-
-/* *************************************
-* console display
-***************************************/
-#define DISPLAY(...) fprintf(stderr, __VA_ARGS__)
-#define DISPLAYLEVEL(l, ...) if (g_displayLevel>=l) { DISPLAY(__VA_ARGS__); }
-static U32 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(stdout); } }
-static const clock_t refreshRate = CLOCKS_PER_SEC * 15 / 100;
-static clock_t g_time = 0;
-
-
-/* *************************************
-* Exceptions
-***************************************/
-#ifndef DEBUG
-# define DEBUG 0
-#endif
-#define DEBUGOUTPUT(...) if (DEBUG) DISPLAY(__VA_ARGS__);
-#define END_PROCESS(error, ...) \
-{ \
- DEBUGOUTPUT("Error defined at %s, line %i : \n", __FILE__, __LINE__); \
- DISPLAYLEVEL(1, "Error %i : ", error); \
- DISPLAYLEVEL(1, __VA_ARGS__); \
- DISPLAYLEVEL(1, "\n"); \
- exit(error); \
-}
-
-
-/* *************************************
-* Benchmark Parameters
-***************************************/
-static U32 g_nbSeconds = NBSECONDS;
-static size_t g_blockSize = 0;
-int g_additionalParam = 0;
-int g_benchSeparately = 0;
-
-void BMK_setNotificationLevel(unsigned level) { g_displayLevel=level; }
-
-void BMK_setAdditionalParam(int additionalParam) { g_additionalParam=additionalParam; }
-
-void BMK_setNbSeconds(unsigned nbSeconds)
-{
- g_nbSeconds = nbSeconds;
- DISPLAYLEVEL(3, "- test >= %u seconds per compression / decompression -\n", g_nbSeconds);
-}
-
-void BMK_setBlockSize(size_t blockSize) { g_blockSize = blockSize; }
-
-void BMK_setBenchSeparately(int separate) { g_benchSeparately = (separate!=0); }
-
/* ********************************************************
* Bench functions