1
0
mirror of https://github.com/facebook/zstd.git synced 2025-07-29 11:21:22 +03:00

bench.c: experimental -r (operate recursively on directories) for Windows and _POSIX_C_SOURCE >= 200112L

This commit is contained in:
inikep
2016-05-10 14:22:55 +02:00
parent ed9a08538c
commit 3733797fcd
6 changed files with 41 additions and 32 deletions

View File

@ -7,7 +7,7 @@ platform:
- x64 - x64
environment: environment:
matrix: matrix:
- PlatformToolset: v100 # - PlatformToolset: v100
- PlatformToolset: v110 - PlatformToolset: v110
- PlatformToolset: v120 - PlatformToolset: v120
- PlatformToolset: v140 - PlatformToolset: v140

View File

@ -26,7 +26,7 @@
/* ************************************* /* *************************************
* Includes * Includes
***************************************/ ***************************************/
#include "util.h" /* Compiler options, UTIL_GetFileSize, UTIL_createFileList, UTIL_sleep */ #include "util.h" /* Compiler options, UTIL_GetFileSize, UTIL_HAS_CREATEFILELIST, UTIL_sleep */
#include <stdlib.h> /* malloc, free */ #include <stdlib.h> /* malloc, free */
#include <string.h> /* memset */ #include <string.h> /* memset */
#include <stdio.h> /* fprintf, fopen, ftello64 */ #include <stdio.h> /* fprintf, fopen, ftello64 */
@ -501,7 +501,7 @@ static void BMK_syntheticTest(int cLevel, int cLevelLast, double compressibility
int BMK_benchFiles(const char** fileNamesTable, unsigned nbFiles, int BMK_benchFiles(const char** fileNamesTable, unsigned nbFiles,
const char* dictFileName, int cLevel, int cLevelLast) const char* dictFileName, int cLevel, int cLevelLast, int recursive)
{ {
double const compressibility = (double)g_compressibilityDefault / 100; double const compressibility = (double)g_compressibilityDefault / 100;
@ -510,15 +510,18 @@ int BMK_benchFiles(const char** fileNamesTable, unsigned nbFiles,
else else
{ {
#ifdef UTIL_HAS_CREATEFILELIST #ifdef UTIL_HAS_CREATEFILELIST
char* buf; if (recursive) {
const char** filenameTable; char* buf;
unsigned i; const char** filenameTable;
nbFiles = UTIL_createFileList(fileNamesTable, nbFiles, MAX_LIST_SIZE, &filenameTable, &buf); unsigned i;
if (filenameTable) { nbFiles = UTIL_createFileList(fileNamesTable, nbFiles, MAX_LIST_SIZE, &filenameTable, &buf);
for (i=0; i<nbFiles; i++) DISPLAYLEVEL(3, "%d %s\n", i, filenameTable[i]); if (filenameTable) {
BMK_benchFileTable(filenameTable, nbFiles, dictFileName, cLevel, cLevelLast); for (i=0; i<nbFiles; i++) DISPLAYLEVEL(3, "%d %s\n", i, filenameTable[i]);
UTIL_freeFileList(filenameTable, buf); BMK_benchFileTable(filenameTable, nbFiles, dictFileName, cLevel, cLevelLast);
UTIL_freeFileList(filenameTable, buf);
}
} }
else BMK_benchFileTable(fileNamesTable, nbFiles, dictFileName, cLevel, cLevelLast);
#else #else
BMK_benchFileTable(fileNamesTable, nbFiles, dictFileName, cLevel, cLevelLast); BMK_benchFileTable(fileNamesTable, nbFiles, dictFileName, cLevel, cLevelLast);
#endif #endif

View File

@ -26,7 +26,7 @@
/* Main function */ /* Main function */
int BMK_benchFiles(const char** fileNamesTable, unsigned nbFiles, int BMK_benchFiles(const char** fileNamesTable, unsigned nbFiles,
const char* dictFileName, int cLevel, int cLevelLast); const char* dictFileName, int cLevel, int cLevelLast, int recursive);
/* Set Parameters */ /* Set Parameters */
void BMK_SetNbIterations(unsigned nbLoops); void BMK_SetNbIterations(unsigned nbLoops);

View File

@ -29,6 +29,7 @@
#include <stdlib.h> /* malloc, free */ #include <stdlib.h> /* malloc, free */
#include <string.h> /* memset */ #include <string.h> /* memset */
#include <stdio.h> /* fprintf, fopen, ftello64 */ #include <stdio.h> /* fprintf, fopen, ftello64 */
#include <time.h> /* clock_t, clock, CLOCKS_PER_SEC */
#include "mem.h" /* read */ #include "mem.h" /* read */
#include "error_private.h" #include "error_private.h"

View File

@ -85,7 +85,7 @@ extern "C" {
# define SET_HIGH_PRIORITY SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS) # define SET_HIGH_PRIORITY SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS)
# define UTIL_sleep(s) Sleep(1000*s) # define UTIL_sleep(s) Sleep(1000*s)
# define UTIL_sleepMilli(milli) Sleep(milli) # define UTIL_sleepMilli(milli) Sleep(milli)
#elif (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) #elif (defined(__unix__) || defined(__unix) || defined(__midipix__) || (defined(__APPLE__) && defined(__MACH__)))
# include <unistd.h> # include <unistd.h>
# include <sys/resource.h> /* setpriority */ # include <sys/resource.h> /* setpriority */
# include <time.h> /* clock_t, nanosleep, clock, CLOCKS_PER_SEC */ # include <time.h> /* clock_t, nanosleep, clock, CLOCKS_PER_SEC */
@ -255,7 +255,7 @@ next:
return nbFiles; return nbFiles;
} }
#elif (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) && defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) /* snprintf, opendir */ #elif (defined(__unix__) || defined(__unix) || defined(__midipix__) || (defined(__APPLE__) && defined(__MACH__))) && defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) /* snprintf, opendir */
# define UTIL_HAS_CREATEFILELIST # define UTIL_HAS_CREATEFILELIST
# include <dirent.h> /* opendir, readdir */ # include <dirent.h> /* opendir, readdir */
# include <limits.h> /* PATH_MAX */ # include <limits.h> /* PATH_MAX */

View File

@ -31,15 +31,13 @@
/*-************************************ /*-************************************
* Compiler Options * Compiler Options
**************************************/ **************************************/
#define _CRT_SECURE_NO_WARNINGS /* Visual : removes warning from strcpy */
#define _POSIX_SOURCE 1 /* triggers fileno() within <stdio.h> on unix */ #define _POSIX_SOURCE 1 /* triggers fileno() within <stdio.h> on unix */
/*-************************************ /*-************************************
* Includes * Includes
**************************************/ **************************************/
#include <stdio.h> /* fprintf, getchar */ #include "util.h" /* Compiler options, UTIL_HAS_CREATEFILELIST */
#include <stdlib.h> /* exit, calloc, free */
#include <string.h> /* strcmp, strlen */ #include <string.h> /* strcmp, strlen */
#include <ctype.h> /* toupper */ #include <ctype.h> /* toupper */
#include "fileio.h" #include "fileio.h"
@ -48,7 +46,7 @@
#endif #endif
#include "zstd_static.h" /* ZSTD_maxCLevel, ZSTD version numbers */ #include "zstd_static.h" /* ZSTD_maxCLevel, ZSTD version numbers */
#ifndef ZSTD_NODICT #ifndef ZSTD_NODICT
# include "dibio.h" /* BMK_benchFiles, BMK_SetNbIterations */ # include "dibio.h"
#endif #endif
@ -148,8 +146,11 @@ static int usage_advanced(const char* programName)
#ifndef ZSTD_NOBENCH #ifndef ZSTD_NOBENCH
DISPLAY( "Benchmark arguments :\n"); DISPLAY( "Benchmark arguments :\n");
DISPLAY( " -b# : benchmark file(s), using # compression level (default : 1) \n"); DISPLAY( " -b# : benchmark file(s), using # compression level (default : 1) \n");
DISPLAY( " -r# : test all compression levels from -bX to # (default: 1)\n"); DISPLAY( " -e# : test all compression levels from -bX to # (default: 1)\n");
DISPLAY( " -i# : iteration loops [1-9](default : 3)\n"); DISPLAY( " -i# : iteration loops [1-9](default : 3)\n");
#ifdef UTIL_HAS_CREATEFILELIST
DISPLAY( " -r : operate recursively on directories\n");
#endif
DISPLAY( " -B# : cut file into independent blocks of size # (default: no block)\n"); DISPLAY( " -B# : cut file into independent blocks of size # (default: no block)\n");
#endif #endif
return 0; return 0;
@ -188,6 +189,7 @@ int main(int argCount, const char** argv)
nextArgumentIsMaxDict=0; nextArgumentIsMaxDict=0;
unsigned cLevel = 1; unsigned cLevel = 1;
unsigned cLevelLast = 1; unsigned cLevelLast = 1;
unsigned recursive = 0;
const char** filenameTable = (const char**)malloc(argCount * sizeof(const char*)); /* argCount >= 1 */ const char** filenameTable = (const char**)malloc(argCount * sizeof(const char*)); /* argCount >= 1 */
unsigned filenameIdx = 0; unsigned filenameIdx = 0;
const char* programName = argv[0]; const char* programName = argv[0];
@ -199,7 +201,7 @@ int main(int argCount, const char** argv)
unsigned dictSelect = g_defaultSelectivityLevel; unsigned dictSelect = g_defaultSelectivityLevel;
/* init */ /* init */
(void)cLevelLast; (void)dictCLevel; /* not used when ZSTD_NOBENCH / ZSTD_NODICT set */ (void)recursive; (void)cLevelLast; (void)dictCLevel; /* not used when ZSTD_NOBENCH / ZSTD_NODICT set */
(void)decode; (void)cLevel; /* not used when ZSTD_NOCOMPRESS set */ (void)decode; (void)cLevel; /* not used when ZSTD_NOCOMPRESS set */
if (filenameTable==NULL) { DISPLAY("not enough memory\n"); exit(1); } if (filenameTable==NULL) { DISPLAY("not enough memory\n"); exit(1); }
displayOut = stderr; displayOut = stderr;
@ -294,6 +296,17 @@ int main(int argCount, const char** argv)
/* Benchmark */ /* Benchmark */
case 'b': bench=1; argument++; break; case 'b': bench=1; argument++; break;
/* range bench (benchmark only) */
case 'e':
/* compression Level */
argument++;
if ((*argument>='0') && (*argument<='9')) {
cLevelLast = 0;
while ((*argument >= '0') && (*argument <= '9'))
cLevelLast *= 10, cLevelLast += *argument++ - '0';
}
break;
/* Modify Nb Iterations (benchmark only) */ /* Modify Nb Iterations (benchmark only) */
case 'i': case 'i':
{ U32 iters= 0; { U32 iters= 0;
@ -305,6 +318,9 @@ int main(int argCount, const char** argv)
} }
break; break;
/* recursive */
case 'r': recursive=1; argument++; break;
/* cut input into blocks (benchmark only) */ /* cut input into blocks (benchmark only) */
case 'B': case 'B':
{ size_t bSize = 0; { size_t bSize = 0;
@ -318,17 +334,6 @@ int main(int argCount, const char** argv)
BMK_SetBlockSize(bSize); BMK_SetBlockSize(bSize);
} }
break; break;
/* range bench (benchmark only) */
case 'r':
/* compression Level */
argument++;
if ((*argument>='0') && (*argument<='9')) {
cLevelLast = 0;
while ((*argument >= '0') && (*argument <= '9'))
cLevelLast *= 10, cLevelLast += *argument++ - '0';
}
break;
#endif /* ZSTD_NOBENCH */ #endif /* ZSTD_NOBENCH */
/* Selection level */ /* Selection level */
@ -390,7 +395,7 @@ int main(int argCount, const char** argv)
if (bench) { if (bench) {
#ifndef ZSTD_NOBENCH #ifndef ZSTD_NOBENCH
BMK_setNotificationLevel(displayLevel); BMK_setNotificationLevel(displayLevel);
BMK_benchFiles(filenameTable, filenameIdx, dictFileName, cLevel, cLevelLast); BMK_benchFiles(filenameTable, filenameIdx, dictFileName, cLevel, cLevelLast, recursive);
#endif #endif
goto _end; goto _end;
} }