summaryrefslogtreecommitdiff
path: root/cleanbench.c
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2008-11-15 05:23:15 +0000
committerMatt Turner <mattst88@gmail.com>2008-11-15 05:23:15 +0000
commit0a0699aba70c04e3e6c5847b47cee75025e96255 (patch)
tree1f56669779fd2d69b6802b9eae52ee89a20bc381 /cleanbench.c
parent991b62808450c54ac721f345d82426fde3e6289f (diff)
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
Diffstat (limited to 'cleanbench.c')
-rw-r--r--cleanbench.c99
1 files changed, 62 insertions, 37 deletions
diff --git a/cleanbench.c b/cleanbench.c
index 66e58ed..6792bce 100644
--- a/cleanbench.c
+++ b/cleanbench.c
@@ -1,11 +1,36 @@
#include <stdio.h>
#include <stdlib.h>
-#include <ctype.h>
+#include <stdint.h>
+#include <stdbool.h>
#include <string.h>
#include <math.h>
+#include <limits.h>
+#include <time.h>
#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<num_scores;i++) {
** observations). See any introduction to statistics.
*/
*c_half_interval=student_t[num_scores-1] * (*sdev) / sqrt((double)num_scores);
-return FALSE;
+return false;
}
/*************