summaryrefslogtreecommitdiff
path: root/cleanbench.c
blob: f50b10a2d2eb2deca35122cac97ac1d092598dc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379

/*
** cleanbench.c
*/

/*******************************************
**             BYTEmark (tm)              **
** BYTE MAGAZINE'S NATIVE MODE BENCHMARKS **
**           FOR CPU/FPU                  **
**             ver 2.0                    **
**       Rick Grehan, BYTE Magazine       **
********************************************
** REVISION HISTORY FOR BENCHMARKS
**  9/94 -- First beta. --RG
**  12/94 -- Bug discovered in some of the integer routines
**    (IDEA, Huffman,...).  Routines were not accurately counting
**    the number of loops.  Fixed. --RG (Thanks to Steve A.)
**  12/94 -- Added routines to calculate and display index
**    values. Indexes based on DELL XPS 90 (90 MHz Pentium).
**  1/95 -- Added Mac time manager routines for more accurate
**    timing on Macintosh (said to be good to 20 usecs) -- RG
**  1/95 -- Re-did all the #defines so they made more
**    sense.  See NMGLOBAL.H -- RG
**  3/95 -- Fixed memory leak in LU decomposition.  Did not
**    invalidate previous results, just made it easier to run.--RG
**  3/95 -- Added TOOLHELP.DLL timing routine to Windows timer. --RG
**  10/95 -- Added memory array & alignment; moved memory
**      allocation out of LU Decomposition -- RG
**
** DISCLAIMER
** The source, executable, and documentation files that comprise
** the BYTEmark benchmarks are made available on an "as is" basis.
** This means that we at BYTE Magazine have made every reasonable
** effort to verify that the there are no errors in the source and
** executable code.  We cannot, however, guarantee that the programs
** are error-free.  Consequently, McGraw-HIll and BYTE Magazine make
** no claims in regard to the fitness of the source code, executable
** code, and documentation of the BYTEmark.
**  Furthermore, BYTE Magazine, McGraw-Hill, and all employees
** of McGraw-Hill cannot be held responsible for any damages resulting
** from the use of this code or the results obtained from using
** this code.
*/

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>

#include "cleanbench.h"
#include "hardware.h"

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);
static double getscore(int fid);

/* Tests-to-do flags...must coincide with test. */
enum {
	NUMSORT,
	STRINGSORT,
	BITFIELD,
	FPEMULATION,
	FOURIER,
	ASSIGNMENT,
	IDEA,
	HUFFMAN,
	NEURAL,
	LINEAR
} tests_t;

#define NUMTESTS 10

/*
** Following array is a collection of flags indicating which
** tests to perform.
*/
int tests_to_do[NUMTESTS];


/*
** Test names
*/
char *ftestnames[] = {
        "NUMERIC SORT    ",
        "STRING SORT     ",
        "BITFIELD        ",
        "FP EMULATION    ",
        "FOURIER         ",
        "ASSIGNMENT      ",
        "IDEA            ",
        "HUFFMAN         ",
        "NEURAL NET      ",
        "LU DECOMPOSITION" };

/*
** Indexes -- Baseline is DELL Pentium XP90
** 11/28/94
*/
double bindex[] = {
    38.993,                     /* Numeric sort */
    2.238,                      /* String sort */
    5829704,                    /* Bitfield */
    2.084,                      /* FP Emulation */
    879.278,                    /* Fourier */
    .2628,                      /* Assignment */
    65.382,                     /* IDEA */
    36.062,                     /* Huffman */
    .6225,                      /* Neural Net */
    19.3031 };                  /* LU Decomposition */

/*
** Indices -- Baseline is a AMD K6-233, 32MB RAM (60ns SDRAM),512k L2 cache,
** Linux kernel 2.0.32, libc-5.4.38, gcc-2.7.2.3)
** Nov/30/97
*/
double lx_bindex[] = {
      118.73, 	    /* Numeric sort */
      14.459,	    /* String sort */
    27910000,	    /* Bitfield */
      9.0314,	    /* FP Emulation */
      1565.5,	    /* Fourier */
      1.0132,	    /* Assignment */
      220.21,	    /* IDEA */
      112.93,	    /* Huffman */
      1.4799,	    /* Neural Net */
      26.732};      /* LU Decomposition */


void (*funcpointer[])(void) =
{       DoNumSort,
        DoStringSort,
        DoBitops,
        DoEmFloat,
        DoFourier,
        DoAssign,
        DoIDEA,
        DoHuffman,
        DoNNET,
        DoLU };

/*************
**** main ****
*************/
int main(int argc, char *argv[]) {
double bmean;           /* Benchmark mean */
double bstdev;          /* Benchmark stdev */
double lx_memindex = 1.0;     /* Linux memory index (mainly integer operations)*/
double lx_intindex = 1.0;     /* Linux integer index */
double lx_fpindex = 1.0;      /* Linux floating-point index */
double intindex = 1.0;        /* Integer index */
double fpindex = 1.0;         /* Floating-point index */
unsigned long bnumrun;  /* # of runs */
int i;                  /* Index */

/*
** We presume all tests will be run unless told
** otherwise
*/
for (i = 0; i < NUMTESTS; i++) {
        tests_to_do[i] = TRUE;
}

puts("BYTEmark* Native Mode Benchmark ver. 2 (10/95)");
puts("Index-split by Andrew D. Balsa (11/97)");
puts("Linux/Unix* port by Uwe F. Mayer (12/96,11/97)");
puts("\nTEST                : Iterations/sec.  : Old Index   : New Index");
puts("                    :                  : Pentium 90* : AMD K6/233*");
puts("--------------------:------------------:-------------:------------");

for(i=NUMSORT;i<NUMTESTS;i++)
{
        if(tests_to_do[i])
        {       printf("%s    :",ftestnames[i]);
                if (0!=bench_with_confidence(i,
                        &bmean,
                        &bstdev,
                        &bnumrun)){
		  puts("\n** WARNING: The current test result is NOT 95 % statistically certain.");
		  puts("** WARNING: The variation among the individual results is too large.");
		  printf("                    :");
		}
                printf(" %15.5g  :  %9.2f  :  %9.2f\n",
                        bmean,bmean/bindex[i],bmean/lx_bindex[i]);
		/*
		** Gather integer or FP indexes
		*/
		if((i==4)||(i==8)||(i==9)){
		  /* FP index */
		  fpindex=fpindex*(bmean/bindex[i]);
		  /* Linux FP index */
		  lx_fpindex=lx_fpindex*(bmean/lx_bindex[i]);
		}
		else{
		  /* Integer index */
		  intindex=intindex*(bmean/bindex[i]);
		  if((i==0)||(i==3)||(i==6)||(i==7))
		    /* Linux integer index */
		    lx_intindex=lx_intindex*(bmean/lx_bindex[i]);
		  else
		    /* Linux memory index */
		    lx_memindex=lx_memindex*(bmean/lx_bindex[i]);
		}
        }
}
        puts("==========================ORIGINAL BYTEMARK RESULTS==========================");
        printf("INTEGER INDEX       : %.3f\n",
                       pow(intindex,(double).142857));
        printf("FLOATING-POINT INDEX: %.3f\n",
                        pow(fpindex,(double).33333));
        puts("Baseline (MSDOS*)   : Pentium* 90, 256 KB L2-cache, Watcom* compiler 10.0");
#ifdef __linux__
        puts("==============================LINUX DATA BELOW===============================");
	hardware();
#include "sysinfoc.c"
        printf("MEMORY INDEX        : %.3f\n",
                       pow(lx_memindex,(double).3333333333));
        printf("INTEGER INDEX       : %.3f\n",
                       pow(lx_intindex,(double).25));
        printf("FLOATING-POINT INDEX: %.3f\n",
                        pow(lx_fpindex,(double).3333333333));
        puts("Baseline (LINUX)    : AMD K6/233*, 512 KB L2-cache, gcc 2.7.2.3, libc-5.4.38");
#endif
puts("* Trademarks are property of their respective holder.");
        return 0;
}

/**************************
** 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.
**
** The above is mathematically questionable, as the statistical theory
** depends on independent observations, and if we exchange data points
** depending on what we already have then this certainly violates
** independence of the observations. Hence I changed this so that at
** most 30 observations are done, but none are deleted as we go
** along. We simply do more runs and hope to get a big enough sample
** size so that things stabilize. Uwe F. Mayer
**
** Return 0 if ok, -1 if failure.  Returns mean
** and std. deviation of results if successful.
*/
static int bench_with_confidence(int fid,       /* Function id */
        double *mean,                   /* Mean of scores */
        double *stdev,                  /* Standard deviation */
        unsigned long *numtries)                /* # of attempts */
{
double myscores[30];            /* Need at least 5 scores, use at most 30 */
double c_half_interval;         /* Confidence half interval */
int i;                          /* Index */
/* double newscore; */          /* For improving confidence interval */

/*
** Get first 5 scores.  Then begin confidence testing.
*/
for (i=0;i<5;i++)
{       (*funcpointer[fid])();
        myscores[i]=getscore(fid);
}
*numtries=5;            /* Show 5 attempts */

/*
** The system allows a maximum of 30 tries before it gives
** up.  Since we've done 5 already, we'll allow 25 more.
*/

/*
** Enter loop to test for confidence criteria.
*/
while(1)
{
        /*
        ** Calculate confidence. Should always return 0.
        */
        if (0!=calc_confidence(myscores,
		*numtries,
                &c_half_interval,
                mean,
                stdev)) return(-1);

        /*
        ** Is the length of the half interval 5% or less of mean?
        ** If so, we can go home.  Otherwise, we have to continue.
        */
        if(c_half_interval/ (*mean) <= (double)0.05)
                break;

	/* We now simply add a new test run and hope that the runs
           finally stabilize, Uwe F. Mayer */
	if(*numtries==30) return(-1);
	(*funcpointer[fid])();
	myscores[*numtries]=getscore(fid);
	*numtries+=1;
}

        return 0;
}

/********************
** calc_confidence **
*********************
** Given a set of numtries scores, calculate the confidence
** half-interval.  We'll also return the sample mean and sample
** standard deviation.
** NOTE: This routines presumes a confidence of 95% and
** a confidence coefficient of .95
** returns 0 if there is an error, otherwise -1
*/
static int calc_confidence(double scores[], /* Array of scores */
		int num_scores,             /* number of scores in array */
                double *c_half_interval,    /* Confidence half-int */
                double *smean,              /* Standard mean */
                double *sdev)               /* Sample stand dev */
{
/* Here is a list of the student-t distribution up to 29 degrees of
   freedom. The value at 0 is bogus, as there is no value for zero
   degrees of freedom. */
double student_t[30]={0.0 , 12.706 , 4.303 , 3.182 , 2.776 , 2.571 ,
                             2.447 , 2.365 , 2.306 , 2.262 , 2.228 ,
                             2.201 , 2.179 , 2.160 , 2.145 , 2.131 ,
                             2.120 , 2.110 , 2.101 , 2.093 , 2.086 ,
                             2.080 , 2.074 , 2.069 , 2.064 , 2.060 ,
		             2.056 , 2.052 , 2.048 , 2.045 };
int i;          /* Index */
if ((num_scores<2) || (num_scores>30)) {
  puts("Internal error: calc_confidence called with an illegal number of scores");
  return(-1);
}
/*
** First calculate mean.
*/
*smean=(double)0.0;
for(i=0;i<num_scores;i++){
  *smean+=scores[i];
}
*smean/=(double)num_scores;

/* Get standard deviation */
*sdev=(double)0.0;
for(i=0;i<num_scores;i++) {
  *sdev+=(scores[i]-(*smean))*(scores[i]-(*smean));
}
*sdev/=(double)(num_scores-1);
*sdev=sqrt(*sdev);

/* Now calculate the length of the confidence half-interval.  For a
** confidence level of 95% our confidence coefficient gives us a
** multiplying factor of the upper .025 quartile of a t distribution
** with num_scores-1 degrees of freedom, and dividing by sqrt(number of
** observations). See any introduction to statistics.
*/
*c_half_interval=student_t[num_scores-1] * (*sdev) / sqrt((double)num_scores);
return(0);
}

/*************
** getscore **
**************
** Return the score for a particular benchmark.
*/
static double getscore(int benchmark) {
        double (*getScore[])(void) = {
                getNumSortScore,
                getStringSortScore,
                getBitfieldScore,
                getEmFloatScore,
                getFourierScore,
                getAssignmentScore,
                getIDEAScore,
                getHuffmanScore,
                getNNETScore,
                getLinearScore
        };

        return (*getScore[benchmark])();
}