From 7ddd55f5d9bdf7362bd5ac07ebc66cca85915242 Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Fri, 14 Nov 2008 00:16:29 +0000 Subject: -- Remove stop watch functions from bitfield.c git-svn-id: svn://mattst88.com/svn/cleanbench/trunk@23 0d43b9a7-5ab2-4d7b-af9d-f64450cef757 --- bitfield.c | 178 +++++++++++++++++++++++++------------------------------------ 1 file changed, 74 insertions(+), 104 deletions(-) diff --git a/bitfield.c b/bitfield.c index 8256e52..6d0cf0b 100644 --- a/bitfield.c +++ b/bitfield.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "nmglobal.h" #include "nbench1.h" @@ -13,7 +14,7 @@ ** BITFIELD OPERATIONS ** *************************/ -static unsigned long DoBitfieldIteration(unsigned long *bitarraybase, +static clock_t DoBitfieldIteration(unsigned long *bitarraybase, unsigned long *bitoparraybase, long bitoparraysize, unsigned long *nbitops); @@ -34,22 +35,20 @@ static void FlipBitRun(unsigned long *bitmap, void DoBitops(void) { - /* Error context string */ - const char *context = "CPU:Bitfields"; - /* Local bitop structure */ - BitOpStruct *locbitopstruct = &global_bitopstruct; - - unsigned long *bitarraybase = NULL; /* Base of bitmap array */ - unsigned long *bitoparraybase = NULL; /* Base of bitmap operations array */ - unsigned long nbitops; /* # of bitfield operations */ - unsigned long accumtime; /* Accumulated time in ticks */ - double iterations; /* # of iterations */ - int ticks; + const char* context = "CPU:Bitfields"; + BitOpStruct* locbitopstruct = &global_bitopstruct; + clock_t total_time = 0; + int iterations = 0; + unsigned long* bitarraybase = NULL; + unsigned long* bitoparraybase = NULL; + unsigned long nbitops; /* ** See if we need to run adjustment code. */ - if (locbitopstruct->adjust == 0) { + if (locbitopstruct->adjust == FALSE) { + locbitopstruct->adjust = TRUE; + bitarraybase = realloc(bitarraybase, locbitopstruct->bitfieldarraysize * sizeof(unsigned long)); if (!bitarraybase) { fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); @@ -75,12 +74,7 @@ DoBitops(void) ** minimum, then de-allocate the array, reallocate a ** larger version, and try again. */ - ticks = DoBitfieldIteration(bitarraybase, - bitoparraybase, - locbitopstruct->bitoparraysize, - &nbitops); - - if (ticks > global_min_ticks) { + if(DoBitfieldIteration(bitarraybase, bitoparraybase, locbitopstruct->bitoparraysize, &nbitops) > global_min_ticks) { break; } @@ -109,14 +103,10 @@ DoBitops(void) ** All's well if we get here. Repeatedly perform bitops until the ** accumulated elapsed time is greater than # of seconds requested. */ - accumtime = 0L; - iterations = 0.0; do { - accumtime += DoBitfieldIteration(bitarraybase, - bitoparraybase, - locbitopstruct->bitoparraysize,&nbitops); - iterations += (double)nbitops; - } while (TicksToSecs(accumtime) < locbitopstruct->request_secs); + total_time += DoBitfieldIteration(bitarraybase, bitoparraybase, locbitopstruct->bitoparraysize,&nbitops); + iterations += nbitops; + } while (total_time / CLOCKS_PER_SEC < locbitopstruct->request_secs); /* ** Clean up, calculate results, and go home. @@ -126,11 +116,7 @@ DoBitops(void) free(bitarraybase); free(bitoparraybase); - locbitopstruct->bitopspersec = iterations / TicksToFracSecs(accumtime); - - if (locbitopstruct->adjust == 0) { - locbitopstruct->adjust = 1; - } + locbitopstruct->bitopspersec = (double)(iterations * CLOCKS_PER_SEC) / (double)total_time; } /************************ @@ -139,90 +125,74 @@ DoBitops(void) ** Perform a single iteration of the bitfield benchmark. ** Return the # of ticks accumulated by the operation. */ -static unsigned long DoBitfieldIteration(unsigned long *bitarraybase, - unsigned long *bitoparraybase, - long bitoparraysize, - unsigned long *nbitops) +static clock_t +DoBitfieldIteration(unsigned long *bitarraybase, unsigned long *bitoparraybase, long bitoparraysize, unsigned long *nbitops) { -long i; /* Index */ -unsigned long bitoffset; /* Offset into bitmap */ -unsigned long elapsed; /* Time to execute */ -/* -** Clear # bitops counter -*/ -*nbitops=0L; - -/* -** Construct a set of bitmap offsets and run lengths. -** The offset can be any random number from 0 to the -** size of the bitmap (in bits). The run length can -** be any random number from 1 to the number of bits -** between the offset and the end of the bitmap. -** Note that the bitmap has 8192 * 32 bits in it. -** (262,144 bits) -*/ -/* -** Reset random number generator so things repeat. -** Also reset the bit array we work on. -** added by Uwe F. Mayer -*/ -randnum((int32_t)13); + clock_t start, stop; + long i; + unsigned long bitoffset; -for (i=0;i