From becd1a927a0fa089a62b0cbc352cdbf224da7286 Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Fri, 14 Nov 2008 02:56:30 +0000 Subject: -- Remove stop watch functions from assignment.c -- Small fixes to numsort.c, stringsort.c, and bitfield.c git-svn-id: svn://mattst88.com/svn/cleanbench/trunk@24 0d43b9a7-5ab2-4d7b-af9d-f64450cef757 --- assignment.c | 167 ++++++++++++++++++++++++----------------------------------- bitfield.c | 45 +++++----------- numsort.c | 2 +- stringsort.c | 2 +- 4 files changed, 83 insertions(+), 133 deletions(-) diff --git a/assignment.c b/assignment.c index d3598c5..2f11ea0 100644 --- a/assignment.c +++ b/assignment.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "nmglobal.h" #include "nbench1.h" @@ -33,7 +34,7 @@ typedef struct { /* ** PROTOTYPES */ -static unsigned long DoAssignIteration(long *arraybase, +static clock_t DoAssignIteration(long *arraybase, unsigned long numarrays); static void LoadAssignArrayWithRand(long *arraybase, unsigned long numarrays); @@ -65,79 +66,62 @@ static void second_assignments(long tableau[][ASSIGNCOLS], ** probably non-optimal constructs. ** */ -void DoAssign(void) +void +DoAssign(void) { -AssignStruct *locassignstruct = &global_assignstruct; /* Local structure ptr */ -long *arraybase = NULL; -char *context = "CPU:Assignment"; -unsigned long accumtime; -double iterations; - -/* -** See if we need to do self adjustment code. -*/ -if(locassignstruct->adjust==0) -{ - /* - ** Self-adjustment code. The system begins by working on 1 - ** array. If it does that in no time, then two arrays - ** are built. This process continues until - ** enough arrays are built to handle the tolerance. - */ - locassignstruct->numarrays=1; - while(1) - { - arraybase = realloc(arraybase, sizeof(long) * ASSIGNROWS * ASSIGNCOLS * locassignstruct->numarrays); - if (!arraybase) { + const char* context = "CPU:Assignment"; + AssignStruct* locassignstruct = &global_assignstruct; /* Local structure ptr */ + long* arraybase = NULL; + unsigned long total_time = 0; + int iterations = 0; + + /* + ** See if we need to do self adjustment code. + */ + if (locassignstruct->adjust == FALSE) { + locassignstruct->adjust = TRUE; + /* + ** Self-adjustment code. The system begins by working on 1 + ** array. If it does that in no time, then two arrays + ** are built. This process continues until + ** enough arrays are built to handle the tolerance. + */ + locassignstruct->numarrays = 1; + while (1) { + arraybase = realloc(arraybase, sizeof(long) * ASSIGNROWS * ASSIGNCOLS * locassignstruct->numarrays); + if (!arraybase) { + fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); + exit(1); + } + + /* + ** Do an iteration of the assignment alg. If the + ** elapsed time is less than or equal to the permitted + ** minimum, then allocate for more arrays and + ** try again. + */ + if (DoAssignIteration(arraybase, locassignstruct->numarrays) > global_min_ticks) { + break; + } + + ++locassignstruct->numarrays; + } + } else { + arraybase = malloc(sizeof(long) * ASSIGNROWS * ASSIGNCOLS * locassignstruct->numarrays); + if (!arraybase) { fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); exit(1); - } - - /* - ** Do an iteration of the assignment alg. If the - ** elapsed time is less than or equal to the permitted - ** minimum, then allocate for more arrays and - ** try again. - */ - if(DoAssignIteration(arraybase, - locassignstruct->numarrays)>global_min_ticks) - break; /* We're ok...exit */ - - locassignstruct->numarrays++; - } -} else { - arraybase = malloc(sizeof(long) * ASSIGNROWS * ASSIGNCOLS * locassignstruct->numarrays); - if (!arraybase) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - exit(1); - } -} - -/* -** All's well if we get here. Do the tests. -*/ -accumtime=0L; -iterations=(double)0.0; - -do { - accumtime+=DoAssignIteration(arraybase, - locassignstruct->numarrays); - iterations+=(double)1.0; -} while(TicksToSecs(accumtime)request_secs); - -/* -** Clean up, calculate results, and go home. Be sure to -** show that we don't have to rerun adjustment code. -*/ -free(arraybase); + } + } -locassignstruct->iterspersec=iterations * - (double)locassignstruct->numarrays / TicksToFracSecs(accumtime); + do { + total_time += DoAssignIteration(arraybase, locassignstruct->numarrays); + ++iterations; + } while (total_time < locassignstruct->request_secs * CLOCKS_PER_SEC); -if(locassignstruct->adjust==0) - locassignstruct->adjust=1; + free(arraybase); -return; + locassignstruct->iterspersec = (double)(iterations * CLOCKS_PER_SEC *locassignstruct->numarrays) / (double)total_time; } @@ -147,42 +131,29 @@ return; ** This routine executes one iteration of the assignment test. ** It returns the number of ticks elapsed in the iteration. */ -static unsigned long DoAssignIteration(long *arraybase, - unsigned long numarrays) +static clock_t +DoAssignIteration(long *arraybase, unsigned long numarrays) { -longptr abase; /* local pointer */ -unsigned long elapsed; /* Elapsed ticks */ -unsigned long i; + clock_t start, stop; + longptr abase; + unsigned long i; -/* -** Set up local pointer -*/ -abase.ptrs.p=arraybase; + abase.ptrs.p=arraybase; -/* -** Load up the arrays with a random table. -*/ -LoadAssignArrayWithRand(arraybase,numarrays); + LoadAssignArrayWithRand(arraybase,numarrays); -/* -** Start the stopwatch -*/ -elapsed=StartStopwatch(); + start = clock(); -/* -** Execute assignment algorithms -*/ -for(i=0;i>6; /* Index is number /64 */ - bitnumb=bit_addr % 64; /* Bit number in longword */ + bindex=bit_addr>>6; /* Index is number /64 */ + bitnumb=bit_addr % 64; /* Bit number in longword */ #else - bindex=bit_addr>>5; /* Index is number /32 */ - bitnumb=bit_addr % 32; /* Bit number in longword */ + bindex=bit_addr>>5; /* Index is number /32 */ + bitnumb=bit_addr % 32; /* Bit number in longword */ #endif - bitmap[bindex]^=(1L<> 6; /* Index is number /64 */ - bitnumb = bit_addr % 64; /* Bit number in word */ - - if (val) { - bitmap[bindex] |= (1L << bitnumb); - } else { - bitmap[bindex] &= ~(1L << bitnumb); - } - bit_addr++; - } -#else if (val) { for (; nbits != 0; nbits--) { bindex = bit_addr >> 6; @@ -271,6 +252,4 @@ void ToggleBitRun(unsigned long *bitmap, /* Bitmap */ bit_addr++; } } -#endif - return; } diff --git a/numsort.c b/numsort.c index f07c995..80e492f 100644 --- a/numsort.c +++ b/numsort.c @@ -87,7 +87,7 @@ DoNumSort (void) do { total_time += DoNumSortIteration(arraybase, numsortstruct->arraysize, numsortstruct->numarrays); ++iterations; - } while (total_time / CLOCKS_PER_SEC < numsortstruct->request_secs); + } while (total_time < numsortstruct->request_secs * CLOCKS_PER_SEC); free(arraybase); diff --git a/stringsort.c b/stringsort.c index b302f69..cbea030 100644 --- a/stringsort.c +++ b/stringsort.c @@ -106,7 +106,7 @@ void DoStringSort(void) do { total_time += DoStringSortIteration(arraybase, strsortstruct->numarrays, strsortstruct->arraysize); iterations += strsortstruct->numarrays; - } while (total_time / CLOCKS_PER_SEC < strsortstruct->request_secs); + } while (total_time < strsortstruct->request_secs * CLOCKS_PER_SEC); free(arraybase); -- cgit v1.2.3