39
39
#define BLOCKSIZE_DEFAULT 0 /* no slicing into blocks */
40
40
#define DICTSIZE (4 KB)
41
41
#define CLEVEL_DEFAULT 3
42
+ #define DICT_ATTACH_METHOD ZSTD_dlm_byCopy
42
43
43
44
#define BENCH_TIME_DEFAULT_S 6
44
45
#define RUN_TIME_DEFAULT_MS 1000
@@ -156,19 +157,6 @@ createDictionaryBuffer(const char* dictionaryName,
156
157
}
157
158
}
158
159
159
- static ZSTD_CDict * createCDictForDedicatedDictSearch (const void * dict , size_t dictSize , int compressionLevel )
160
- {
161
- ZSTD_CCtx_params * params = ZSTD_createCCtxParams ();
162
- ZSTD_CCtxParams_init (params , compressionLevel );
163
- ZSTD_CCtxParams_setParameter (params , ZSTD_c_enableDedicatedDictSearch , 1 );
164
- ZSTD_CCtxParams_setParameter (params , ZSTD_c_compressionLevel , compressionLevel );
165
-
166
- ZSTD_CDict * cdict = ZSTD_createCDict_advanced2 (dict , dictSize , ZSTD_dlm_byCopy , ZSTD_dct_auto , params , ZSTD_defaultCMem );
167
-
168
- ZSTD_freeCCtxParams (params );
169
- return cdict ;
170
- }
171
-
172
160
/*! BMK_loadFiles() :
173
161
* Loads `buffer`, with content from files listed within `fileNamesTable`.
174
162
* Fills `buffer` entirely.
@@ -461,14 +449,12 @@ static void freeCDictCollection(cdict_collection_t cdictc)
461
449
}
462
450
463
451
/* returns .buffers=NULL if operation fails */
464
- static cdict_collection_t createCDictCollection (const void * dictBuffer , size_t dictSize , size_t nbCDict , int cLevel , int dedicatedDictSearch )
452
+ static cdict_collection_t createCDictCollection (const void * dictBuffer , size_t dictSize , size_t nbCDict , ZSTD_dictContentType_e dictContentType , ZSTD_CCtx_params * cctxParams )
465
453
{
466
454
ZSTD_CDict * * const cdicts = malloc (nbCDict * sizeof (ZSTD_CDict * ));
467
455
if (cdicts == NULL ) return kNullCDictCollection ;
468
456
for (size_t dictNb = 0 ; dictNb < nbCDict ; dictNb ++ ) {
469
- cdicts [dictNb ] = dedicatedDictSearch ?
470
- createCDictForDedicatedDictSearch (dictBuffer , dictSize , cLevel ) :
471
- ZSTD_createCDict (dictBuffer , dictSize , cLevel );
457
+ cdicts [dictNb ] = ZSTD_createCDict_advanced2 (dictBuffer , dictSize , DICT_ATTACH_METHOD , dictContentType , cctxParams , ZSTD_defaultCMem );
472
458
CONTROL (cdicts [dictNb ] != NULL );
473
459
}
474
460
cdict_collection_t cdictc ;
@@ -735,7 +721,7 @@ int bench(const char** fileNameTable, unsigned nbFiles,
735
721
size_t blockSize , int clevel ,
736
722
unsigned nbDictMax , unsigned nbBlocks ,
737
723
unsigned nbRounds , int benchCompression ,
738
- int dedicatedDictSearch )
724
+ ZSTD_dictContentType_e dictContentType , ZSTD_CCtx_params * cctxParams )
739
725
{
740
726
int result = 0 ;
741
727
@@ -786,13 +772,11 @@ int bench(const char** fileNameTable, unsigned nbFiles,
786
772
/* dictionary determination */
787
773
buffer_t const dictBuffer = createDictionaryBuffer (dictionary ,
788
774
srcs .buffer .ptr ,
789
- srcs . slices . capacities , srcs . slices .nbSlices ,
775
+ srcSlices . capacities , srcSlices .nbSlices ,
790
776
DICTSIZE );
791
777
CONTROL (dictBuffer .ptr != NULL );
792
778
793
- ZSTD_CDict * const cdict = dedicatedDictSearch ?
794
- createCDictForDedicatedDictSearch (dictBuffer .ptr , dictBuffer .size , clevel ) :
795
- ZSTD_createCDict (dictBuffer .ptr , dictBuffer .size , clevel );
779
+ ZSTD_CDict * const cdict = ZSTD_createCDict_advanced2 (dictBuffer .ptr , dictBuffer .size , DICT_ATTACH_METHOD , dictContentType , cctxParams , ZSTD_defaultCMem );
796
780
CONTROL (cdict != NULL );
797
781
798
782
size_t const cTotalSizeNoDict = compressBlocks (NULL , dstSlices , srcSlices , NULL , clevel );
@@ -815,14 +799,14 @@ int bench(const char** fileNameTable, unsigned nbFiles,
815
799
816
800
unsigned const nbDicts = nbDictMax ? nbDictMax : nbBlocks ;
817
801
818
- cdict_collection_t const cdictionaries = createCDictCollection (dictBuffer .ptr , dictBuffer .size , nbDicts , clevel , dedicatedDictSearch );
802
+ cdict_collection_t const cdictionaries = createCDictCollection (dictBuffer .ptr , dictBuffer .size , nbDicts , dictContentType , cctxParams );
819
803
CONTROL (cdictionaries .cdicts != NULL );
820
804
821
805
ddict_collection_t const ddictionaries = createDDictCollection (dictBuffer .ptr , dictBuffer .size , nbDicts );
822
806
CONTROL (ddictionaries .ddicts != NULL );
823
807
824
808
if (benchCompression ) {
825
- size_t const dictMem = ZSTD_estimateCDictSize (dictBuffer .size , ZSTD_dlm_byCopy );
809
+ size_t const dictMem = ZSTD_estimateCDictSize (dictBuffer .size , DICT_ATTACH_METHOD );
826
810
size_t const allDictMem = dictMem * nbDicts ;
827
811
DISPLAYLEVEL (3 , "generating %u dictionaries, using %.1f MB of memory \n" ,
828
812
nbDicts , (double )allDictMem / (1 MB ));
@@ -836,7 +820,7 @@ int bench(const char** fileNameTable, unsigned nbFiles,
836
820
837
821
freeBufferCollection (resultCollection );
838
822
} else {
839
- size_t const dictMem = ZSTD_estimateDDictSize (dictBuffer .size , ZSTD_dlm_byCopy );
823
+ size_t const dictMem = ZSTD_estimateDDictSize (dictBuffer .size , DICT_ATTACH_METHOD );
840
824
size_t const allDictMem = dictMem * nbDicts ;
841
825
DISPLAYLEVEL (3 , "generating %u dictionaries, using %.1f MB of memory \n" ,
842
826
nbDicts , (double )allDictMem / (1 MB ));
@@ -927,6 +911,11 @@ int usage(const char* exeName)
927
911
DISPLAY ("--nbBlocks=#: use # blocks for bench (default: one per file) \n" );
928
912
DISPLAY ("--nbDicts=# : create # dictionaries for bench (default: one per block) \n" );
929
913
DISPLAY ("-h : help (this text) \n" );
914
+ DISPLAY (" \n" );
915
+ DISPLAY ("Advanced Options (see zstd.h for documentation) : \n" );
916
+ DISPLAY ("--dedicated-dict-search\n" );
917
+ DISPLAY ("--dict-content-type=#\n" );
918
+ DISPLAY ("--dict-attach-pref=#\n" );
930
919
return 0 ;
931
920
}
932
921
@@ -956,6 +945,8 @@ int main (int argc, const char** argv)
956
945
size_t blockSize = BLOCKSIZE_DEFAULT ;
957
946
unsigned nbDicts = 0 ; /* determine nbDicts automatically: 1 dictionary per block */
958
947
unsigned nbBlocks = 0 ; /* determine nbBlocks automatically, from source and blockSize */
948
+ ZSTD_dictContentType_e dictContentType = ZSTD_dct_auto ;
949
+ ZSTD_dictAttachPref_e dictAttachPref = ZSTD_dictDefaultAttach ;
959
950
960
951
for (int argNb = 1 ; argNb < argc ; argNb ++ ) {
961
952
const char * argument = argv [argNb ];
@@ -972,6 +963,8 @@ int main (int argc, const char** argv)
972
963
if (longCommandWArg (& argument , "--nbBlocks=" )) { nbBlocks = readU32FromChar (& argument ); continue ; }
973
964
if (longCommandWArg (& argument , "--clevel=" )) { cLevel = (int )readU32FromChar (& argument ); continue ; }
974
965
if (longCommandWArg (& argument , "--dedicated-dict-search" )) { dedicatedDictSearch = 1 ; continue ; }
966
+ if (longCommandWArg (& argument , "--dict-content-type=" )) { dictContentType = (int )readU32FromChar (& argument ); continue ; }
967
+ if (longCommandWArg (& argument , "--dict-attach-pref=" )) { dictAttachPref = (int )readU32FromChar (& argument ); continue ; }
975
968
if (longCommandWArg (& argument , "-" )) { cLevel = (int )readU32FromChar (& argument ); continue ; }
976
969
/* anything that's not a command is a filename */
977
970
nameTable [nameIdx ++ ] = argument ;
@@ -989,10 +982,17 @@ int main (int argc, const char** argv)
989
982
nameTable = NULL ; /* UTIL_createFileNamesTable() takes ownership of nameTable */
990
983
}
991
984
992
- int result = bench (filenameTable -> fileNames , (unsigned )filenameTable -> tableSize , dictionary , blockSize , cLevel , nbDicts , nbBlocks , nbRounds , benchCompression , dedicatedDictSearch );
985
+ ZSTD_CCtx_params * cctxParams = ZSTD_createCCtxParams ();
986
+ ZSTD_CCtxParams_init (cctxParams , cLevel );
987
+ ZSTD_CCtxParams_setParameter (cctxParams , ZSTD_c_enableDedicatedDictSearch , dedicatedDictSearch );
988
+ ZSTD_CCtxParams_setParameter (cctxParams , ZSTD_c_nbWorkers , 0 );
989
+ ZSTD_CCtxParams_setParameter (cctxParams , ZSTD_c_forceAttachDict , dictAttachPref );
990
+
991
+ int result = bench (filenameTable -> fileNames , (unsigned )filenameTable -> tableSize , dictionary , blockSize , cLevel , nbDicts , nbBlocks , nbRounds , benchCompression , dictContentType , cctxParams );
993
992
994
993
UTIL_freeFileNamesTable (filenameTable );
995
994
free (nameTable );
995
+ ZSTD_freeCCtxParams (cctxParams );
996
996
997
997
return result ;
998
998
}
0 commit comments