@@ -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,14 @@ void WriteStats(POSITION *plspace, WORD par, WORD checkLogType)
164156 char humanGenTermsText [HUMANSTRLEN ] = "" ;
165157 char humanTermsLeftText [HUMANSTRLEN ] = "" ;
166158 char humanBytesText [HUMANSTRLEN ] = "" ;
159+ char humanUnsortedBytesText [HUMANSTRLEN ] = "" ;
160+ char humanComparisonsText [HUMANSTRLEN ] = "" ;
167161 if ( AC .HumanStatsFlag ) {
168162 HumanString (humanGenTermsText , (float )(S -> GenTerms ), humanTermsSuffix );
169163 HumanString (humanTermsLeftText , (float )(S -> TermsLeft ), humanTermsSuffix );
170164 HumanString (humanBytesText , (float )(BASEPOSITION (* plspace )), humanBytesSuffix );
165+ HumanString (humanUnsortedBytesText , (float )(S -> verbUnsortedSize ), humanBytesSuffix );
166+ HumanString (humanComparisonsText , (float )(S -> verbComparisons ), humanTermsSuffix );
171167 }
172168
173169 MLOCK (ErrorMessageLock );
@@ -315,6 +311,23 @@ void WriteStats(POSITION *plspace, WORD par, WORD checkLogType)
315311 MesPrint ("%s" , buf );
316312 }
317313
314+ if ( par == STATSPOSTSORT ) {
315+ if ( AC .SortVerbose ) {
316+ snprintf (buf , sizeof (buf ), "%24s Unsorted bytes =%11ld%s" ,
317+ "" ,S -> verbUnsortedSize ,humanUnsortedBytesText );
318+ MesPrint ("%s" , buf );
319+ snprintf (buf , sizeof (buf ), "%24s Small Buffer =%5ld,%5ld" ,
320+ "" ,S -> verbSBsortTerms ,S -> verbSBsortCap );
321+ MesPrint ("%s" , buf );
322+ snprintf (buf , sizeof (buf ), "%24s Large Buffer =%5ld,%5ld" ,
323+ "" ,S -> verbLBsortPatches ,S -> verbLBsortCap );
324+ MesPrint ("%s" , buf );
325+ snprintf (buf , sizeof (buf ), "%24s Comparisons =%11ld%s" ,
326+ "" ,S -> verbComparisons ,humanComparisonsText );
327+ MesPrint ("%s" , buf );
328+ }
329+ }
330+
318331#ifdef WITHSTATS
319332 MesPrint ("Total number of writes: %l, reads: %l, seeks, %l"
320333 ,numwrites ,numreads ,numseeks );
@@ -362,14 +375,6 @@ int NewSort(PHEAD0)
362375 }
363376 if ( AR .sLevel == 0 ) {
364377
365- #ifdef COUNTCOMPARES
366- #ifdef WITHPTHREADS
367- numcompares [AT .identity ] = 0 ;
368- #else
369- numcompares [0 ] = 0 ;
370- #endif
371- #endif
372-
373378 AN .FunSorts [0 ] = AT .S0 ;
374379 if ( AR .PolyFun == 0 ) { AT .S0 -> PolyFlag = 0 ; }
375380 else if ( AR .PolyFunType == 1 ) { AT .S0 -> PolyFlag = 1 ; }
@@ -408,6 +413,13 @@ int NewSort(PHEAD0)
408413
409414 PUTZERO(AN.OldPosOut);
410415*/
416+ // Zero the SortVerbose counters:
417+ S -> verbComparisons = 0 ;
418+ S -> verbSBsortTerms = 0 ;
419+ S -> verbSBsortCap = 0 ;
420+ S -> verbLBsortPatches = 0 ;
421+ S -> verbLBsortCap = 0 ;
422+ S -> verbUnsortedSize = 0 ;
411423 return (0 );
412424}
413425
@@ -621,6 +633,10 @@ LONG EndSort(PHEAD WORD *buffer, int par)
621633/*
622634 The large buffer is too full. Merge and write it
623635*/
636+ // Update SortVerbose counters
637+ if ( S -> lPatch >= S -> MaxPatches ) S -> verbLBsortPatches ++ ;
638+ else S -> verbLBsortCap ++ ;
639+
624640#ifdef GZIPDEBUG
625641 MLOCK (ErrorMessageLock );
626642 MesPrint ("%w EndSort: lPatch = %d, MaxPatches = %d,lFill = %x, sSpace = %ld, MaxTer = %d, lTop = %x"
@@ -977,18 +993,6 @@ LONG EndSort(PHEAD WORD *buffer, int par)
977993 }
978994 }
979995
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-
992996 return (retval );
993997WorkSpaceError :
994998 MLOCK (ErrorMessageLock );
@@ -2344,15 +2348,8 @@ WORD Compare1(PHEAD WORD *term1, WORD *term2, WORD level)
23442348 WORD prevorder ;
23452349 WORD count = -1 , localPoly , polyhit = -1 ;
23462350
2347- #ifdef COUNTCOMPARES
2348- if ( AR .sLevel == 0 ) {
2349- #ifdef WITHPTHREADS
2350- numcompares [AT .identity ]++ ;
2351- #else
2352- numcompares [0 ]++ ;
2353- #endif
2354- }
2355- #endif
2351+ // Update SortVerbose counter
2352+ S -> verbComparisons ++ ;
23562353
23572354 if ( S -> PolyFlag ) {
23582355/*
@@ -4252,6 +4249,9 @@ int StoreTerm(PHEAD WORD *term)
42524249 POSITION pp ;
42534250 LONG lSpace , sSpace , RetCode , over , tover ;
42544251
4252+ // Update SortVerbose counters
4253+ S -> verbUnsortedSize += * term * sizeof (* term );
4254+
42554255 if ( ( ( AP .PreDebug & DUMPTOSORT ) == DUMPTOSORT ) && AR .sLevel == 0 ) {
42564256#ifdef WITHPTHREADS
42574257 snprintf ((char * )(THRbuf ),100 ,"StoreTerm(%d)" ,AT .identity );
@@ -4266,6 +4266,10 @@ int StoreTerm(PHEAD WORD *term)
42664266/*
42674267 The small buffer is full. It has to be sorted and written.
42684268*/
4269+ // Update SortVerbose counters
4270+ if ( S -> sTerms >= S -> TermsInSmall ) S -> verbSBsortTerms ++ ;
4271+ else S -> verbSBsortCap ++ ;
4272+
42694273 tover = over = S -> sTerms ;
42704274 ss = S -> sPointer ;
42714275 ss [over ] = 0 ;
@@ -4298,6 +4302,10 @@ int StoreTerm(PHEAD WORD *term)
42984302/*
42994303 The large buffer is too full. Merge and write it
43004304*/
4305+ // Update SortVerbose counters
4306+ if ( S -> lPatch >= S -> MaxPatches ) S -> verbLBsortPatches ++ ;
4307+ else S -> verbLBsortCap ++ ;
4308+
43014309 if ( MergePatches (1 ) ) goto StoreCall ;
43024310/*
43034311 pp = S->SizeInFile[1];
0 commit comments