From 0a0699aba70c04e3e6c5847b47cee75025e96255 Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Sat, 15 Nov 2008 05:23:15 +0000 Subject: Use stdbool.h, bool, true, false instead of manually defining git-svn-id: svn://mattst88.com/svn/cleanbench/trunk@60 0d43b9a7-5ab2-4d7b-af9d-f64450cef757 --- assignment.c | 7 +++-- bitfield.c | 7 +++-- cleanbench.c | 99 +++++++++++++++++++++++++++++++++++++---------------------- cleanbench.h | 25 --------------- fourier.c | 7 +++-- fpemulation.c | 7 +++-- huffman.c | 7 +++-- idea.c | 7 +++-- linear.c | 7 +++-- neural.c | 28 ++++++++--------- numsort.c | 9 +++--- stringsort.c | 21 +++++++------ 12 files changed, 119 insertions(+), 112 deletions(-) diff --git a/assignment.c b/assignment.c index afed56f..a4f4d03 100644 --- a/assignment.c +++ b/assignment.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -76,10 +77,10 @@ DoAssign(void) clock_t total_time = 0; int iterations = 0; static int num_arrays = 1; - static int is_adjusted = FALSE; + static bool is_adjusted = false; - if (is_adjusted == FALSE) { - is_adjusted = TRUE; + if (is_adjusted == false) { + is_adjusted = true; /* ** Self-is_adjustedment code. The system begins by working on 1 ** array. If it does that in no time, then two arrays diff --git a/bitfield.c b/bitfield.c index 314a193..a9042c2 100644 --- a/bitfield.c +++ b/bitfield.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -49,11 +50,11 @@ DoBitops(void) clock_t total_time = 0; int iterations = 0; unsigned long nbitops; - static int is_adjusted = FALSE; + static bool is_adjusted = false; static int bitop_array_size = 30; - if (is_adjusted == FALSE) { - is_adjusted = TRUE; + if (is_adjusted == false) { + is_adjusted = true; bitarray = realloc(bitarray, ARRAY_SIZE * sizeof(unsigned long)); if (!bitarray) { diff --git a/cleanbench.c b/cleanbench.c index 66e58ed..6792bce 100644 --- a/cleanbench.c +++ b/cleanbench.c @@ -1,11 +1,36 @@ #include #include -#include +#include +#include #include #include +#include +#include #include "cleanbench.h" -#include "hardware.h" +#include "randnum.h" + +void DoNumSort(void); +void DoStringSort(void); +void DoBitops(void); +void DoEmFloat(void); +void DoFourier(void); +void DoAssign(void); +void DoIDEA(void); +void DoHuffman(void); +void DoNNET(void); +void DoLU(void); + +double getNumSortScore(void); +double getStringSortScore(void); +double getBitfieldScore(void); +double getEmFloatScore(void); +double getFourierScore(void); +double getAssignmentScore(void); +double getIDEAScore(void); +double getHuffmanScore(void); +double getNNETScore(void); +double getLinearScore(void); static int bench_with_confidence(int fid, double *mean, double *stdev, unsigned long *numtries); static int calc_confidence(double scores[], int num_scores, double *c_half_interval,double *smean, double *sdev); @@ -29,7 +54,7 @@ enum { int main(int argc, char *argv[]) { - const char* test_name[] = { + const char* benchmark_name[] = { "NUMERIC SORT ", "FP EMULATION ", "IDEA ", @@ -46,7 +71,7 @@ main(int argc, char *argv[]) ** Indexes -- Baseline is DELL Pentium XP90 ** 11/28/94 */ - const double bindex[] = { + const double old_index[] = { 38.993, /* Numeric sort */ 2.084, /* FP Emulation */ 65.382, /* IDEA */ @@ -64,7 +89,7 @@ main(int argc, char *argv[]) ** Linux kernel 2.0.32, libc-5.4.38, gcc-2.7.2.3) ** Nov/30/97 */ - const double linux_bindex[] = { + const double linux_index[] = { 118.73, /* Numeric sort */ 9.0314, /* FP Emulation */ 220.21, /* IDEA */ @@ -77,39 +102,39 @@ main(int argc, char *argv[]) 26.732 /* LU Decomposition */ }; - double linux_memindex = 1.0; /* Linux memory index (mainly integer operations)*/ - double linux_intindex = 1.0; /* Linux integer index */ - double linux_fpindex = 1.0; /* Linux floating-point index */ - double intindex = 1.0; /* Integer index */ - double fpindex = 1.0; /* Floating-point index */ - double bmean; /* Benchmark mean */ - double bstdev; /* Benchmark stdev */ - unsigned long bnumrun; /* # of runs */ - int test; /* Index */ + double linux_memindex = 1.0; /* Linux memory index */ + double linux_intindex = 1.0; /* Linux integer index */ + double linux_fpindex = 1.0; /* Linux floating-point index */ + double intindex = 1.0; /* Old Integer index */ + double fpindex = 1.0; /* Old Floating-point index */ + double average; /* Average of benchmark results */ + double std_dev; /* Standard deviation of benchmark results */ + unsigned long runs; /* # of runs */ + int benchmark = 0; puts( "TEST : Iterations/sec. : Old Index : New Index\n" " : : Pentium 90 : AMD K6/233\n" "--------------------:------------------:-------------:------------"); - for (test = 0; test < NUMTESTS; test++) { - printf("%s :", test_name[test]); + for (; benchmark < NUMTESTS; benchmark++) { + printf("%s :", benchmark_name[benchmark]); - if (!bench_with_confidence(test, &bmean, &bstdev, &bnumrun)) { - printf( "\n** WARNING: The current test result is NOT 95 %% statistically certain.\n" + if (!bench_with_confidence(benchmark, &average, &std_dev, &runs)) { + printf( "\n** WARNING: The current benchmark result is NOT 95 %% statistically certain.\n" "** WARNING: The variation among the individual results is too large.\n" " :"); } - printf(" %15.5g : %9.2f : %9.2f\n", bmean, bmean / bindex[test], bmean / linux_bindex[test]); + printf(" %15.5g : %9.2f : %9.2f\n", average, average / old_index[benchmark], average / linux_index[benchmark]); - if (test >= FOURIER) { - fpindex *= bmean / bindex[test]; - linux_fpindex *= bmean / linux_bindex[test]; + if (benchmark >= FOURIER) { + fpindex *= average /old_index[benchmark]; + linux_fpindex *= average / linux_index[benchmark]; } else { - intindex *= bmean / bindex[test]; - if (test <= HUFFMAN) { - linux_intindex *= bmean / linux_bindex[test]; + intindex *= average / old_index[benchmark]; + if (benchmark <= HUFFMAN) { + linux_intindex *= average / linux_index[benchmark]; } else { - linux_memindex *= bmean / linux_bindex[test]; + linux_memindex *= average / linux_index[benchmark]; } } } @@ -132,9 +157,9 @@ main(int argc, char *argv[]) /************************** ** bench_with_confidence ** *************************** -** Given a benchmark id that indicates a function, this routine -** repeatedly calls that benchmark, seeking to collect and replace -** scores to get 5 that meet the confidence criteria. +** Given a benchmark, this routine repeatedly calls that benchmark, +** seeking to collect and replace scores to get 5 that meet the +** confidence criteria. ** ** The above is mathematically questionable, as the statistical theory ** depends on independent observations, and if we exchange data points @@ -144,8 +169,8 @@ main(int argc, char *argv[]) ** along. We simply do more runs and hope to get a big enough sample ** size so that things stabilize. Uwe F. Mayer ** -** Return TRUE if ok, FALSE if failure. Returns mean -** and std. deviation of results if successful. +** Return true; false on failure. Returns mean +** and standard deviation through argument list if successful. */ static int bench_with_confidence(int benchmark, double *mean, /* Mean of scores */ @@ -189,13 +214,13 @@ for (i=0;i<5;i++) while(1) { /* - ** Calculate confidence. Should always return TRUE + ** Calculate confidence. Should always return true */ if (0!=calc_confidence(myscores, *numtries, &c_half_interval, mean, - stdev)) return FALSE; + stdev)) return false; /* ** Is the length of the half interval 5% or less of mean? @@ -206,13 +231,13 @@ while(1) /* We now simply add a new test run and hope that the runs finally stabilize, Uwe F. Mayer */ - if(*numtries==30) return FALSE; + if(*numtries==30) return false; (*funcpointer[benchmark])(); myscores[*numtries]=getScore(benchmark); *numtries+=1; } - return TRUE; + return true; } /******************** @@ -243,7 +268,7 @@ double student_t[30]={0.0 , 12.706 , 4.303 , 3.182 , 2.776 , 2.571 , int i; /* Index */ if ((num_scores<2) || (num_scores>30)) { puts("Internal error: calc_confidence called with an illegal number of scores"); - return TRUE; + return true; } /* ** First calculate mean. @@ -269,7 +294,7 @@ for(i=0;i #include #include +#include #include #include #include @@ -44,11 +45,11 @@ DoFourier(void) double* bbase = NULL; clock_t total_time = 0; int iterations = 0; - static int is_adjusted = FALSE; + static bool is_adjusted = false; static int array_size = 100; - if (is_adjusted == FALSE) { - is_adjusted = TRUE; + if (is_adjusted == false) { + is_adjusted = true; while (1) { abase = realloc(abase, array_size * sizeof(double)); diff --git a/fpemulation.c b/fpemulation.c index 4089e71..bd4b320 100644 --- a/fpemulation.c +++ b/fpemulation.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -48,7 +49,7 @@ DoEmFloat(void) clock_t total_time = 0; int iterations = 0; unsigned long i = 1; - static int is_adjusted = FALSE; + static bool is_adjusted = false; static long loops = 0; abase = malloc(ARRAY_SIZE * sizeof(InternalFPF)); @@ -76,8 +77,8 @@ DoEmFloat(void) SetupCPUEmFloatArrays(abase, bbase); /* FIXME: ugly */ /* See if we need to do self-adjusting code.*/ - if (is_adjusted == FALSE) { - is_adjusted = TRUE; + if (is_adjusted == false) { + is_adjusted = true; /* ** Do an iteration of the tests. If the elapsed time is diff --git a/huffman.c b/huffman.c index 4ef7259..e9b1e0d 100644 --- a/huffman.c +++ b/huffman.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -71,7 +72,7 @@ DoHuffman(void) char* plaintext = NULL; clock_t total_time = 0; int iterations = 0; - static int is_adjusted = FALSE; + static bool is_adjusted = false; static int loops = 100; /* @@ -132,8 +133,8 @@ DoHuffman(void) /* ** See if we need to perform self adjustment loop. */ - if (is_adjusted == FALSE) { - is_adjusted = TRUE; + if (is_adjusted == false) { + is_adjusted = true; /* ** Do self-adjustment. This involves initializing the ** # of loops and increasing the loop count until we diff --git a/idea.c b/idea.c index 902446e..0f97ddf 100644 --- a/idea.c +++ b/idea.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -72,7 +73,7 @@ DoIDEA(void) IDEAkey Z, DK; uint16_t userkey[8]; int i; - static int is_adjusted = FALSE; + static bool is_adjusted = false; static int loops = 100; randnum(3); @@ -131,8 +132,8 @@ DoIDEA(void) /* ** See if we need to perform self adjustment loop. */ - if (is_adjusted == FALSE) { - is_adjusted = TRUE; + if (is_adjusted == false) { + is_adjusted = true; /* ** Do self-adjustment. This involves initializing the ** # of loops and increasing the loop count until we diff --git a/linear.c b/linear.c index fe19af8..32d5af6 100644 --- a/linear.c +++ b/linear.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -77,7 +78,7 @@ DoLU(void) int n; int i; static int num_arrays = 0; - static int is_adjusted = FALSE; + static bool is_adjusted = false; /* ** Our first step is to build a "solvable" problem. This @@ -107,8 +108,8 @@ DoLU(void) ** auto-adjust. If so, repeatedly call the DoLUIteration routine, ** increasing the number of solutions per iteration as you go. */ - if (is_adjusted == FALSE) { - is_adjusted = TRUE; + if (is_adjusted == false) { + is_adjusted = true; for(i=1;i<=ARRAY_MAX;i++) { diff --git a/neural.c b/neural.c index c3fe5e5..cf03dac 100644 --- a/neural.c +++ b/neural.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -45,8 +46,6 @@ */ #define LOOP_MAX 500000L -#define T 1 /* TRUE */ -#define F 0 /* FALSE */ #define ERR -1 #define MAXPATS 10 /* max number of patterns in data file */ #define IN_X_SIZE 5 /* number of neurodes/row of input layer */ @@ -86,7 +85,7 @@ double avg_out_error[MAXPATS]; /* average error each pattern */ int iteration_count; /* number of passes thru network so far */ int numpats; /* number of patterns in data file */ int numpasses; /* number of training passes through data file */ -int learned; /* flag--if TRUE, network has learned all patterns */ +int learned; /* flag--if true, network has learned all patterns */ static clock_t DoNNetIteration(unsigned long nloops); static void do_mid_forward(int patt); @@ -122,7 +121,7 @@ DoNNET(void) /* const char* context="CPU:NNET"; */ /* Since we never fprintf errors here, we don't need this */ clock_t total_time = 0; int iterations = 0; - static int is_adjusted = FALSE; + static bool is_adjusted = false; static int loops = 1; /* @@ -147,8 +146,8 @@ DoNNET(void) /* ** See if we need to perform self adjustment loop. */ - if (is_adjusted == FALSE) { - is_adjusted = TRUE; + if (is_adjusted == false) { + is_adjusted = true; /* ** Do self-adjustment. This involves initializing the ** # of loops and increasing the loop count until we @@ -196,9 +195,9 @@ while(nloops--) randomize_wts(); zero_changes(); iteration_count=1; - learned = F; + learned = false; numpasses = 0; - while (learned == F) + while (!learned) { for (patt=0; patt= STOP) result = F; - if (tot_out_error[i] >= 16.0) error = T; + if (worst_error >= STOP) result = false; + if (tot_out_error[i] >= 16.0) error = true; } -if (error == T) result = ERR; +if (error) result = ERR; #ifdef DEBUG diff --git a/numsort.c b/numsort.c index e997707..46eb432 100644 --- a/numsort.c +++ b/numsort.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -21,7 +22,7 @@ ** The following constant NUMARRAYSIZE determines the ** default # of elements in each numeric array */ -#define ARRAY_SIZE 8111L +#define ARRAY_SIZE 8111 static clock_t DoNumSortIteration(long *array, unsigned int num_arrays); static void LoadNumArrayWithRand(long *array, unsigned int num_arrays); @@ -44,10 +45,10 @@ DoNumSort (void) clock_t total_time = 0; int iterations = 0; static int num_arrays = 1; - static int is_adjusted = FALSE; + static bool is_adjusted = false; - if (is_adjusted == FALSE) { - is_adjusted = TRUE; + if (is_adjusted == false) { + is_adjusted = true; /* ** Self-is_adjustedment code. The system begins by sorting 1 ** array. If it does that in no time, then two arrays diff --git a/stringsort.c b/stringsort.c index d19d14f..a8ff4f3 100644 --- a/stringsort.c +++ b/stringsort.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -18,7 +19,7 @@ ** The following constant STRINGARRAYSIZE determines ** the default # of bytes allocated to each string array. */ -#define ARRAY_SIZE 8111L +#define ARRAY_SIZE 8111 static clock_t DoStringSortIteration(unsigned char *array, @@ -59,10 +60,10 @@ void DoStringSort(void) clock_t total_time = 0; int iterations = 0; static int num_arrays = 1; - static int is_adjusted = FALSE; + static bool is_adjusted = false; - if (is_adjusted == FALSE) { - is_adjusted = TRUE; + if (is_adjusted == false) { + is_adjusted = true; /* ** Initialize the number of arrays. */ @@ -422,7 +423,7 @@ for(i=top; i>0; --i) ** 2) A pointer to a string array ** 3) The number of elements in the string array ** 4) Offsets to two strings (a & b) -** This function returns TRUE if string a is < string b. +** This function returns true if string a is < string b. */ static int str_is_less(unsigned long *optrarray, /* Offset pointers */ unsigned char *strarray, /* String array */ @@ -446,18 +447,18 @@ slen=strncmp((char *)(strarray+*(optrarray+a)), if(slen==0) { /* - ** They match. Return TRUE if the length of a + ** They match. Return true if the length of a ** is greater than the length of b. */ if(*(strarray+*(optrarray+a)) > *(strarray+*(optrarray+b))) - return TRUE; - return FALSE; + return true; + return false; } -if(slen<0) return TRUE; /* a is strictly less than b */ +if(slen<0) return true; /* a is strictly less than b */ -return FALSE; /* Only other possibility */ +return false; /* Only other possibility */ } /************ -- cgit v1.2.3