Skip to content

Commit 9ebc2e2

Browse files
committed
perf: tform: remove default-enabled compare count
For scripts which are dominated by level-0 sorting, counting the compares (and not even printing the result) leads to a large performance impact. Disable the counting by default. The per-thread counter still leads to a performance impact, though it is smaller.
1 parent 2e1b84e commit 9ebc2e2

1 file changed

Lines changed: 32 additions & 6 deletions

File tree

sources/sort.c

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,13 @@ extern LONG nummallocs;
7272
extern LONG numfrees;
7373
#endif
7474

75-
LONG numcompares;
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
7682

7783
/*
7884
#] Includes :
@@ -659,7 +665,13 @@ int NewSort(PHEAD0)
659665
}
660666
if ( AR.sLevel == 0 ) {
661667

662-
numcompares = 0;
668+
#ifdef COUNTCOMPARES
669+
#ifdef WITHPTHREADS
670+
numcompares[AT.identity] = 0;
671+
#else
672+
numcompares[0] = 0;
673+
#endif
674+
#endif
663675

664676
AN.FunSorts[0] = AT.S0;
665677
if ( AR.PolyFun == 0 ) { AT.S0->PolyFlag = 0; }
@@ -1267,11 +1279,19 @@ LONG EndSort(PHEAD WORD *buffer, int par)
12671279
newout = 0;
12681280
}
12691281
}
1270-
/*
1282+
1283+
#ifdef COUNTCOMPARES
12711284
if ( AR.sLevel < 0 ) {
1272-
MesPrint(" number of calls to compare was %l",numcompares);
1285+
#ifdef WITHPTHREADS
1286+
MLOCK(ErrorMessageLock);
1287+
MesPrint(">>>number of calls to Compare: %l (tid %d)", numcompares[AT.identity], AT.identity);
1288+
MUNLOCK(ErrorMessageLock);
1289+
#else
1290+
MesPrint(">>>number of calls to Compare: %l", numcompares[0]);
1291+
#endif
12731292
}
1274-
*/
1293+
#endif
1294+
12751295
return(retval);
12761296
WorkSpaceError:
12771297
MLOCK(ErrorMessageLock);
@@ -2627,9 +2647,15 @@ WORD Compare1(PHEAD WORD *term1, WORD *term2, WORD level)
26272647
WORD prevorder;
26282648
WORD count = -1, localPoly, polyhit = -1;
26292649

2650+
#ifdef COUNTCOMPARES
26302651
if ( AR.sLevel == 0 ) {
2631-
numcompares++;
2652+
#ifdef WITHPTHREADS
2653+
numcompares[AT.identity]++;
2654+
#else
2655+
numcompares[0]++;
2656+
#endif
26322657
}
2658+
#endif
26332659

26342660
if ( S->PolyFlag ) {
26352661
/*

0 commit comments

Comments
 (0)