@@ -72,14 +72,6 @@ extern LONG nummallocs;
7272extern LONG numfrees ;
7373#endif
7474
75- //#define COUNTCOMPARES
76- #ifdef COUNTCOMPARES
77- // This needs to be large enough for the number of threads.
78- // It is hardcoded here, but 1024 should be enough.
79- // Enabling this has a performance impact.
80- LONG numcompares [1024 ];
81- #endif
82-
8375/*
8476 #] Includes :
8577 #[ SortUtilities :
@@ -164,10 +156,12 @@ void WriteStats(POSITION *plspace, WORD par, WORD checkLogType)
164156 char humanGenTermsText [HUMANSTRLEN ] = "" ;
165157 char humanTermsLeftText [HUMANSTRLEN ] = "" ;
166158 char humanBytesText [HUMANSTRLEN ] = "" ;
159+ char humanComparisonsText [HUMANSTRLEN ] = "" ;
167160 if ( AC .HumanStatsFlag ) {
168161 HumanString (humanGenTermsText , (float )(S -> GenTerms ), humanTermsSuffix );
169162 HumanString (humanTermsLeftText , (float )(S -> TermsLeft ), humanTermsSuffix );
170163 HumanString (humanBytesText , (float )(BASEPOSITION (* plspace )), humanBytesSuffix );
164+ HumanString (humanComparisonsText , (float )(S -> verbComparisons ), humanTermsSuffix );
171165 }
172166
173167 MLOCK (ErrorMessageLock );
@@ -315,6 +309,20 @@ void WriteStats(POSITION *plspace, WORD par, WORD checkLogType)
315309 MesPrint ("%s" , buf );
316310 }
317311
312+ if ( par == STATSPOSTSORT ) {
313+ if ( AC .SortVerbose ) {
314+ snprintf (buf , sizeof (buf ), "%24s Comparisons =%11ld%s" ,
315+ "" ,S -> verbComparisons ,humanComparisonsText );
316+ MesPrint ("%s" , buf );
317+ snprintf (buf , sizeof (buf ), "%24s Small Buffer =%5ld,%5ld" ,
318+ "" ,S -> verbSBsortTerms ,S -> verbSBsortCap );
319+ MesPrint ("%s" , buf );
320+ snprintf (buf , sizeof (buf ), "%24s Large Buffer =%5ld,%5ld" ,
321+ "" ,S -> verbLBsortPatches ,S -> verbLBsortCap );
322+ MesPrint ("%s" , buf );
323+ }
324+ }
325+
318326#ifdef WITHSTATS
319327 MesPrint ("Total number of writes: %l, reads: %l, seeks, %l"
320328 ,numwrites ,numreads ,numseeks );
@@ -362,14 +370,6 @@ int NewSort(PHEAD0)
362370 }
363371 if ( AR .sLevel == 0 ) {
364372
365- #ifdef COUNTCOMPARES
366- #ifdef WITHPTHREADS
367- numcompares [AT .identity ] = 0 ;
368- #else
369- numcompares [0 ] = 0 ;
370- #endif
371- #endif
372-
373373 AN .FunSorts [0 ] = AT .S0 ;
374374 if ( AR .PolyFun == 0 ) { AT .S0 -> PolyFlag = 0 ; }
375375 else if ( AR .PolyFunType == 1 ) { AT .S0 -> PolyFlag = 1 ; }
@@ -408,6 +408,12 @@ int NewSort(PHEAD0)
408408
409409 PUTZERO(AN.OldPosOut);
410410*/
411+ // Zero the SortVerbose counters:
412+ S -> verbComparisons = 0 ;
413+ S -> verbSBsortTerms = 0 ;
414+ S -> verbSBsortCap = 0 ;
415+ S -> verbLBsortPatches = 0 ;
416+ S -> verbLBsortCap = 0 ;
411417 return (0 );
412418}
413419
@@ -621,6 +627,10 @@ LONG EndSort(PHEAD WORD *buffer, int par)
621627/*
622628 The large buffer is too full. Merge and write it
623629*/
630+ // Update SortVerbose counters
631+ if ( S -> lPatch >= S -> MaxPatches ) S -> verbLBsortPatches ++ ;
632+ else S -> verbLBsortCap ++ ;
633+
624634#ifdef GZIPDEBUG
625635 MLOCK (ErrorMessageLock );
626636 MesPrint ("%w EndSort: lPatch = %d, MaxPatches = %d,lFill = %x, sSpace = %ld, MaxTer = %d, lTop = %x"
@@ -977,18 +987,6 @@ LONG EndSort(PHEAD WORD *buffer, int par)
977987 }
978988 }
979989
980- #ifdef COUNTCOMPARES
981- if ( AR .sLevel < 0 ) {
982- #ifdef WITHPTHREADS
983- MLOCK (ErrorMessageLock );
984- MesPrint (">>>number of calls to Compare: %l (tid %d)" , numcompares [AT .identity ], AT .identity );
985- MUNLOCK (ErrorMessageLock );
986- #else
987- MesPrint (">>>number of calls to Compare: %l" , numcompares [0 ]);
988- #endif
989- }
990- #endif
991-
992990 return (retval );
993991WorkSpaceError :
994992 MLOCK (ErrorMessageLock );
@@ -2344,15 +2342,10 @@ WORD Compare1(PHEAD WORD *term1, WORD *term2, WORD level)
23442342 WORD prevorder ;
23452343 WORD count = -1 , localPoly , polyhit = -1 ;
23462344
2347- #ifdef COUNTCOMPARES
23482345 if ( AR .sLevel == 0 ) {
2349- #ifdef WITHPTHREADS
2350- numcompares [AT .identity ]++ ;
2351- #else
2352- numcompares [0 ]++ ;
2353- #endif
2346+ // Update SortVerbose counter at ground level only
2347+ S -> verbComparisons ++ ;
23542348 }
2355- #endif
23562349
23572350 if ( S -> PolyFlag ) {
23582351/*
@@ -4266,6 +4259,10 @@ int StoreTerm(PHEAD WORD *term)
42664259/*
42674260 The small buffer is full. It has to be sorted and written.
42684261*/
4262+ // Update SortVerbose counters
4263+ if ( S -> sTerms >= S -> TermsInSmall ) S -> verbSBsortTerms ++ ;
4264+ else S -> verbSBsortCap ++ ;
4265+
42694266 tover = over = S -> sTerms ;
42704267 ss = S -> sPointer ;
42714268 ss [over ] = 0 ;
@@ -4298,6 +4295,10 @@ int StoreTerm(PHEAD WORD *term)
42984295/*
42994296 The large buffer is too full. Merge and write it
43004297*/
4298+ // Update SortVerbose counters
4299+ if ( S -> lPatch >= S -> MaxPatches ) S -> verbLBsortPatches ++ ;
4300+ else S -> verbLBsortCap ++ ;
4301+
43014302 if ( MergePatches (1 ) ) goto StoreCall ;
43024303/*
43034304 pp = S->SizeInFile[1];
0 commit comments