diff options
author | Matt Turner <mattst88@gmail.com> | 2008-11-14 00:16:29 +0000 |
---|---|---|
committer | Matt Turner <mattst88@gmail.com> | 2008-11-14 00:16:29 +0000 |
commit | 7ddd55f5d9bdf7362bd5ac07ebc66cca85915242 (patch) | |
tree | 901362e5fbe44ddfddbbc1ae39b1f99efe950857 | |
parent | 7af55db3dc3e0287daa1085e186dcc5dffe1083a (diff) |
-- Remove stop watch functions from bitfield.c
git-svn-id: svn://mattst88.com/svn/cleanbench/trunk@23 0d43b9a7-5ab2-4d7b-af9d-f64450cef757
-rw-r--r-- | bitfield.c | 178 |
1 files changed, 74 insertions, 104 deletions
@@ -4,6 +4,7 @@ #include <string.h> #include <math.h> #include <limits.h> +#include <time.h> #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<global_bitopstruct.bitfieldarraysize;i++) -{ + /* + ** 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(13); + + for (i = 0; i < global_bitopstruct.bitfieldarraysize; i++) { #ifdef _LP64 - *(bitarraybase+i)=(unsigned long)0x5555555555555555; + *(bitarraybase+i) = 0x5555555555555555UL; #else - *(bitarraybase+i)=(unsigned long)0x55555555; + *(bitarraybase+i) = 0x55555555UL; #endif -} + } -randnum((int32_t)13); -/* end of addition of code */ + randnum(13); -for (i=0;i<bitoparraysize;i++) -{ - /* First item is offset */ - /* *(bitoparraybase+i+i)=bitoffset=abs_randwc(262140L); */ - *(bitoparraybase+i+i)=bitoffset=abs_randwc((int32_t)262140); + for (i = 0; i < bitoparraysize; i++) { + /* First item is offset */ + *(bitoparraybase + i + i) = bitoffset = abs_randwc((int32_t)262140); - /* Next item is run length */ - /* *nbitops+=*(bitoparraybase+i+i+1L)=abs_randwc(262140L-bitoffset);*/ - *nbitops+=*(bitoparraybase+i+i+1L)=abs_randwc((int32_t)262140-bitoffset); -} + /* Next item is run length */ + *nbitops += *(bitoparraybase + i + i + 1L) = abs_randwc((int32_t)262140 - bitoffset); + } -/* -** Array of offset and lengths built...do an iteration of -** the test. -** Start the stopwatch. -*/ -elapsed=StartStopwatch(); + start = clock(); + + for(i = 0; i < bitoparraysize; i++) { + switch(i % 3) { + case 2: /* Complement run of bits */ + FlipBitRun(bitarraybase, + *(bitoparraybase+i+i), + *(bitoparraybase+i+i+1)); + break; + default: + ToggleBitRun(bitarraybase, + *(bitoparraybase+i+i), + *(bitoparraybase+i+i+1), + !i); + break; + } + } -/* -** Loop through array off offset/run length pairs. -** Execute operation based on modulus of index. -*/ -for(i = 0; i < bitoparraysize; i++) { - int asdf = i % 3; - switch(asdf) { - case 2: /* Complement run of bits */ - FlipBitRun(bitarraybase, - *(bitoparraybase+i+i), - *(bitoparraybase+i+i+1)); - break; - default: - ToggleBitRun(bitarraybase, - *(bitoparraybase+i+i), - *(bitoparraybase+i+i+1), - !i); - break; - } -} + stop = clock(); -/* -** Return elapsed time -*/ -return(StopStopwatch(elapsed)); + return stop - start; } /*************** |