summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2008-11-14 02:56:30 +0000
committerMatt Turner <mattst88@gmail.com>2008-11-14 02:56:30 +0000
commitbecd1a927a0fa089a62b0cbc352cdbf224da7286 (patch)
tree64f56aec30db3bb561a5b298e78296e50cfebc5d
parent7ddd55f5d9bdf7362bd5ac07ebc66cca85915242 (diff)
-- 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
-rw-r--r--assignment.c167
-rw-r--r--bitfield.c45
-rw-r--r--numsort.c2
-rw-r--r--stringsort.c2
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 <string.h>
#include <math.h>
#include <limits.h>
+#include <time.h>
#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)<locassignstruct->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<numarrays;i++)
-{ /* abase.ptrs.p+=i*ASSIGNROWS*ASSIGNCOLS; */
- /* Fixed by Eike Dierks */
- Assignment(*abase.ptrs.ap);
- abase.ptrs.p+=ASSIGNROWS*ASSIGNCOLS;
-}
+ for (i = 0; i < numarrays; i++) {
+ /* abase.ptrs.p+=i*ASSIGNROWS*ASSIGNCOLS; */
+ /* Fixed by Eike Dierks */
+ Assignment(*abase.ptrs.ap);
+ abase.ptrs.p += ASSIGNROWS * ASSIGNCOLS;
+ }
-/*
-** Get elapsed time
-*/
-return(StopStopwatch(elapsed));
+ stop = clock();
+
+ return stop - start;
}
/****************************
diff --git a/bitfield.c b/bitfield.c
index 6d0cf0b..4b70206 100644
--- a/bitfield.c
+++ b/bitfield.c
@@ -200,27 +200,23 @@ DoBitfieldIteration(unsigned long *bitarraybase, unsigned long *bitoparraybase,
****************
** Complements a run of bits.
*/
-static void FlipBitRun(unsigned long *bitmap, /* Bit map */
- unsigned long bit_addr, /* Bit address */
- unsigned long nbits) /* # of bits to flip */
+static void
+FlipBitRun(unsigned long *bitmap, unsigned long bit_addr, unsigned long nbits)
{
-unsigned long bindex; /* Index into array */
-unsigned long bitnumb; /* Bit number */
+ unsigned long bindex; /* Index into array */
+ unsigned long bitnumb; /* Bit number */
-while(nbits--)
-{
+ while (nbits--) {
#ifdef _LP64
- bindex=bit_addr>>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<<bitnumb);
- bit_addr++;
-}
-
-return;
+ bitmap[bindex]^=(1L<<bitnumb);
+ bit_addr++;
+ }
}
/*****************************
@@ -237,21 +233,6 @@ void ToggleBitRun(unsigned long *bitmap, /* Bitmap */
unsigned long bindex; /* Index into array */
unsigned long bitnumb; /* Bit number */
-#if 0
- while (nbits != 0) {
- nbits--;
-
- bindex = bit_addr >> 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);