diff options
author | Matt Turner <mattst88@gmail.com> | 2008-11-14 00:01:53 +0000 |
---|---|---|
committer | Matt Turner <mattst88@gmail.com> | 2008-11-14 00:01:53 +0000 |
commit | 7af55db3dc3e0287daa1085e186dcc5dffe1083a (patch) | |
tree | ae00ea8a9b2608d1fa18c659be4983c4dad593e6 /numsort.c | |
parent | 682804e40ceb3c611923e2fac3c1d04626faab00 (diff) |
-- Remove useless stop watch functions from numsort.c and stringsort.c
git-svn-id: svn://mattst88.com/svn/cleanbench/trunk@22 0d43b9a7-5ab2-4d7b-af9d-f64450cef757
Diffstat (limited to 'numsort.c')
-rw-r--r-- | numsort.c | 63 |
1 files changed, 21 insertions, 42 deletions
@@ -4,6 +4,7 @@ #include <string.h> #include <math.h> #include <limits.h> +#include <time.h> #include "nmglobal.h" #include "nbench1.h" @@ -15,7 +16,7 @@ ** This test implements a heapsort algorithm, performed on an ** array of longs. */ -static unsigned long DoNumSortIteration(long *arraybase, unsigned long arraysize, unsigned int numarrays); +static clock_t DoNumSortIteration(long *arraybase, unsigned long arraysize, unsigned int numarrays); static void LoadNumArrayWithRand(long *array, unsigned long arraysize, unsigned int numarrays); static inline void NumHeapSort(long *array, unsigned long bottom, unsigned long top); static inline void NumSift(long *array, unsigned long min, unsigned long max); @@ -29,19 +30,17 @@ static inline void NumSift(long *array, unsigned long min, unsigned long max); void DoNumSort (void) { - /* Error context string pointer */ - const char *context = "CPU:Numeric Sort"; - /* Local pointer to global struct */ - SortStruct * numsortstruct = &global_numsortstruct; - - long accumtime; /* Accumulated time */ - double iterations; /* Iteration counter */ - long *arraybase = NULL; /* Base pointers of array */ + const char* context = "CPU:Numeric Sort"; + SortStruct* numsortstruct = &global_numsortstruct; + clock_t total_time = 0; + int iterations = 0; + long* arraybase = NULL; /* ** See if we need to do self adjustment code. */ - if (numsortstruct->adjust == 0) { + if (numsortstruct->adjust == FALSE) { + numsortstruct->adjust = TRUE; /* ** Self-adjustment code. The system begins by sorting 1 ** array. If it does that in no time, then two arrays @@ -49,6 +48,7 @@ DoNumSort (void) ** enough arrays are built to handle the tolerance. */ numsortstruct->numarrays = 1; + while (1) { arraybase = realloc(arraybase, numsortstruct->numarrays * numsortstruct->arraysize * sizeof(long)); if (!arraybase) { @@ -83,25 +83,15 @@ DoNumSort (void) ** All's well if we get here. Repeatedly perform sorts until the ** accumulated elapsed time is greater than # of seconds requested. */ - accumtime = 0L; - iterations = 0.0; do { - accumtime += DoNumSortIteration(arraybase, numsortstruct->arraysize, numsortstruct->numarrays); - iterations += 1.0; - } while ( TicksToSecs(accumtime) < numsortstruct->request_secs ); + total_time += DoNumSortIteration(arraybase, numsortstruct->arraysize, numsortstruct->numarrays); + ++iterations; + } while (total_time / CLOCKS_PER_SEC < numsortstruct->request_secs); - /* - ** Clean up, calculate results, and go home. Be sure to - ** show that we don't have to rerun adjustment code. - */ free(arraybase); - numsortstruct->sortspersec = iterations * (double)numsortstruct->numarrays / TicksToFracSecs(accumtime); - - if (numsortstruct->adjust == 0) { - numsortstruct->adjust = 1; - } + numsortstruct->sortspersec = (double)(iterations * numsortstruct->numarrays * CLOCKS_PER_SEC) / (double)total_time; } /*********************** @@ -111,10 +101,10 @@ DoNumSort (void) ** sort benchmark. It returns the number of ticks ** elapsed for the iteration. */ -static unsigned long +static clock_t DoNumSortIteration(long *arraybase, unsigned long arraysize, unsigned int numarrays) { - unsigned long elapsed; /* Elapsed ticks */ + clock_t start, stop; unsigned long i; /* @@ -122,24 +112,15 @@ DoNumSortIteration(long *arraybase, unsigned long arraysize, unsigned int numarr */ LoadNumArrayWithRand(arraybase, arraysize, numarrays); - /* - ** Start the stopwatch - */ - elapsed = StartStopwatch(); + start = clock(); - /* - ** Execute a heap of heapsorts - */ for (i = 0; i < numarrays; i++) { - NumHeapSort(arraybase + i * arraysize, 0L, arraysize - 1L); + NumHeapSort(&arraybase[i], 0L, arraysize - 1L); } - /* - ** Get elapsed time - */ - elapsed = StopStopwatch(elapsed); + stop = clock(); - return(elapsed); + return stop - start; } /************************* @@ -148,9 +129,7 @@ DoNumSortIteration(long *arraybase, unsigned long arraysize, unsigned int numarr ** Load up an array with random longs. */ static void -LoadNumArrayWithRand(long *array, /* Pointer to arrays */ - unsigned long arraysize, - unsigned int numarrays) /* # of elements in array */ +LoadNumArrayWithRand(long *array, unsigned long arraysize, unsigned int numarrays) { long i; /* Used for index */ long *darray; /* Destination array pointer */ |