diff options
Diffstat (limited to 'stringsort.c')
-rw-r--r-- | stringsort.c | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/stringsort.c b/stringsort.c index a91ff6d..71e6045 100644 --- a/stringsort.c +++ b/stringsort.c @@ -14,13 +14,18 @@ ** STRING HEAPSORT ** ********************/ -static clock_t DoStringSortIteration(unsigned char *arraybase, - unsigned int num_arrays, - unsigned long arraysize); +/* +** The following constant STRINGARRAYSIZE determines +** the default # of bytes allocated to each string array. +*/ +#define ARRAY_SIZE 8111L + + +static clock_t DoStringSortIteration(unsigned char *array, + unsigned int num_arrays); static unsigned long *LoadStringArray(unsigned char *strarray, unsigned int num_arrays, - unsigned long *strings, - unsigned long arraysize); + unsigned long *strings); static void stradjust(unsigned long *optrarray, unsigned char *strarray, unsigned long nstrings, @@ -49,7 +54,7 @@ void DoStringSort(void) { const char* context = "CPU:String Sort"; SortStruct* strsortstruct = &global_strsortstruct; - unsigned char* arraybase = NULL; + unsigned char* array = NULL; clock_t total_time = 0; int iterations = 0; static int num_arrays = 1; @@ -66,8 +71,8 @@ void DoStringSort(void) ** bytes to protect memory as strings move around ** (this can happen during string adjustment) */ - arraybase = realloc(arraybase, (strsortstruct->arraysize + 100) * num_arrays); - if (!arraybase) { + array = realloc(array, (ARRAY_SIZE + 100) * num_arrays); + if (!array) { fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); exit(1); } @@ -78,7 +83,7 @@ void DoStringSort(void) ** minimum, then de-allocate the array, reallocate a ** an additional array, and try again. */ - if (DoStringSortIteration(arraybase, num_arrays, strsortstruct->arraysize) > MINIMUM_TICKS) { + if (DoStringSortIteration(array, num_arrays) > MINIMUM_TICKS) { break; } @@ -89,19 +94,19 @@ void DoStringSort(void) ** We don't have to perform self adjustment code. ** Simply allocate the space for the array. */ - arraybase = malloc((strsortstruct->arraysize + 100) * num_arrays); - if (!arraybase) { + array = malloc((ARRAY_SIZE + 100) * num_arrays); + if (!array) { fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); exit(1); } } do { - total_time += DoStringSortIteration(arraybase, num_arrays, strsortstruct->arraysize); + total_time += DoStringSortIteration(array, num_arrays); iterations += num_arrays; } while (total_time < MINIMUM_SECONDS * CLOCKS_PER_SEC); - free(arraybase); + free(array); strsortstruct->results = (double)(iterations * CLOCKS_PER_SEC) / (double)total_time; } @@ -115,7 +120,7 @@ void DoStringSort(void) ** array. */ static clock_t -DoStringSortIteration(unsigned char *arraybase, unsigned int num_arrays,unsigned long arraysize) +DoStringSortIteration(unsigned char *array, unsigned int num_arrays) { unsigned long *optrarray; /* Offset pointer array */ clock_t start, stop; @@ -127,21 +132,21 @@ DoStringSortIteration(unsigned char *arraybase, unsigned int num_arrays,unsigned /* ** Load up the array(s) with random numbers */ - optrarray=LoadStringArray(arraybase,num_arrays,&nstrings,arraysize); + optrarray=LoadStringArray(array,num_arrays,&nstrings); /* ** Set temp base pointers...they will be modified as the ** benchmark proceeds. */ tempobase = optrarray; - tempsbase = arraybase; + tempsbase = array; start = clock(); for(i = 0; i < num_arrays; i++) { StrHeapSort(tempobase, tempsbase, nstrings, 0L, nstrings - 1); tempobase += nstrings; /* Advance base pointers */ - tempsbase += arraysize+100; + tempsbase += ARRAY_SIZE + 100; } stop = clock(); @@ -162,8 +167,7 @@ DoStringSortIteration(unsigned char *arraybase, unsigned int num_arrays,unsigned */ static unsigned long *LoadStringArray(unsigned char *strarray, /* String array */ unsigned int num_arrays, /* # of arrays */ - unsigned long *nstrings, /* # of strings */ - unsigned long arraysize) /* Size of array */ + unsigned long *nstrings) /* # of strings */ { unsigned char *tempsbase; /* Temporary string base pointer */ unsigned long *optrarray; /* Local for pointer */ @@ -200,8 +204,8 @@ do */ /* stringlength=(unsigned char)((1+abs_randwc(76L)) & 0xFFL);*/ stringlength=(unsigned char)((1+abs_randwc((int32_t)76)) & 0xFFL); - if((unsigned long)stringlength+curroffset+1L>=arraysize) - { stringlength=(unsigned char)((arraysize-curroffset-1L) & + if((unsigned long)stringlength+curroffset+1L>=ARRAY_SIZE) + { stringlength=(unsigned char)((ARRAY_SIZE-curroffset-1L) & 0xFF); fullflag=1; /* Indicates a full */ } @@ -237,8 +241,8 @@ do k=1; tempsbase=strarray; while(k<num_arrays) -{ tempsbase+=arraysize+100; /* Set base */ - for(l=0;l<arraysize;l++) +{ tempsbase += ARRAY_SIZE + 100; /* Set base */ + for (l = 0; l < ARRAY_SIZE; l++) tempsbase[l]=strarray[l]; k++; } |