summaryrefslogtreecommitdiff
path: root/numsort.c
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2008-11-14 22:27:04 +0000
committerMatt Turner <mattst88@gmail.com>2008-11-14 22:27:04 +0000
commit7225b0865e8c7697fce69224640142374b22364d (patch)
tree27fb27187a9f6010485a2f5bc0716ce1e0af7acd /numsort.c
parent341997c711b8d0ba7edf70cced84762e2a82d996 (diff)
-- Remove numarrays member from structs in favor of a local variable
git-svn-id: svn://mattst88.com/svn/cleanbench/trunk@43 0d43b9a7-5ab2-4d7b-af9d-f64450cef757
Diffstat (limited to 'numsort.c')
-rw-r--r--numsort.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/numsort.c b/numsort.c
index 0e77e93..1186d54 100644
--- a/numsort.c
+++ b/numsort.c
@@ -16,8 +16,8 @@
** This test implements a heapsort algorithm, performed on an
** array of longs.
*/
-static clock_t DoNumSortIteration(long *arraybase, unsigned long arraysize, unsigned int numarrays);
-static void LoadNumArrayWithRand(long *array, unsigned long arraysize, unsigned int numarrays);
+static clock_t DoNumSortIteration(long *arraybase, unsigned long arraysize, unsigned int num_arrays);
+static void LoadNumArrayWithRand(long *array, unsigned long arraysize, unsigned int num_arrays);
static inline void NumHeapSort(long *array, unsigned long bottom, unsigned long top);
static inline void NumSift(long *array, unsigned long min, unsigned long max);
@@ -36,6 +36,8 @@ DoNumSort (void)
int iterations = 0;
long* arraybase = NULL;
+ int num_arrays = 1;
+
/*
** See if we need to do self adjustment code.
*/
@@ -47,10 +49,9 @@ DoNumSort (void)
** are built and sorted. This process continues until
** enough arrays are built to handle the tolerance.
*/
- numsortstruct->numarrays = 1;
while (1) {
- arraybase = realloc(arraybase, numsortstruct->numarrays * numsortstruct->arraysize * sizeof(long));
+ arraybase = realloc(arraybase, num_arrays * numsortstruct->arraysize * sizeof(long));
if (!arraybase) {
fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
exit(1);
@@ -62,17 +63,17 @@ DoNumSort (void)
** minimum, then allocate for more arrays and
** try again.
*/
- if (DoNumSortIteration(arraybase, numsortstruct->arraysize, numsortstruct->numarrays) > MINIMUM_TICKS) {
+ if (DoNumSortIteration(arraybase, numsortstruct->arraysize, num_arrays) > MINIMUM_TICKS) {
break;
}
- if (numsortstruct->numarrays > NUMNUMARRAYS) {
+ if (num_arrays > NUMNUMARRAYS) {
puts("CPU:NSORT -- NUMNUMARRAYS hit.");
}
- ++numsortstruct->numarrays;
+ ++num_arrays;
}
} else {
- arraybase = malloc(numsortstruct->numarrays * numsortstruct->arraysize * sizeof(long));
+ arraybase = malloc(num_arrays * numsortstruct->arraysize * sizeof(long));
if (!arraybase) {
fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
exit(1);
@@ -85,13 +86,13 @@ DoNumSort (void)
*/
do {
- total_time += DoNumSortIteration(arraybase, numsortstruct->arraysize, numsortstruct->numarrays);
+ total_time += DoNumSortIteration(arraybase, numsortstruct->arraysize, num_arrays);
++iterations;
} while (total_time < MINIMUM_SECONDS * CLOCKS_PER_SEC);
free(arraybase);
- numsortstruct->results = (double)(iterations * numsortstruct->numarrays * CLOCKS_PER_SEC) / (double)total_time;
+ numsortstruct->results = (double)(iterations * num_arrays * CLOCKS_PER_SEC) / (double)total_time;
}
/***********************
@@ -102,7 +103,7 @@ DoNumSort (void)
** elapsed for the iteration.
*/
static clock_t
-DoNumSortIteration(long *arraybase, unsigned long arraysize, unsigned int numarrays)
+DoNumSortIteration(long *arraybase, unsigned long arraysize, unsigned int num_arrays)
{
clock_t start, stop;
unsigned long i;
@@ -110,11 +111,11 @@ DoNumSortIteration(long *arraybase, unsigned long arraysize, unsigned int numarr
/*
** Load up the array with random numbers
*/
- LoadNumArrayWithRand(arraybase, arraysize, numarrays);
+ LoadNumArrayWithRand(arraybase, arraysize, num_arrays);
start = clock();
- for (i = 0; i < numarrays; i++) {
+ for (i = 0; i < num_arrays; i++) {
NumHeapSort(&arraybase[i], 0L, arraysize - 1L);
}
@@ -129,7 +130,7 @@ DoNumSortIteration(long *arraybase, unsigned long arraysize, unsigned int numarr
** Load up an array with random longs.
*/
static void
-LoadNumArrayWithRand(long *array, unsigned long arraysize, unsigned int numarrays)
+LoadNumArrayWithRand(long *array, unsigned long arraysize, unsigned int num_arrays)
{
long i; /* Used for index */
long *darray; /* Destination array pointer */
@@ -147,7 +148,7 @@ LoadNumArrayWithRand(long *array, unsigned long arraysize, unsigned int numarray
** first into each of the others.
*/
darray = array;
- while (--numarrays) {
+ while (--num_arrays) {
darray += arraysize;
memcpy(darray, array, arraysize * sizeof(long));
}