home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
BENCHMARKS
/
dhrystone.c
< prev
next >
Wrap
C/C++ Source or Header
|
2009-11-06
|
11KB
|
416 lines
/*
* "DHRYSTONE" Benchmark Program
*
* The following program contains statments of a high-level
* programming language (C) in a distribution considered
* representative:
*
* assignments 53%
* control statements 32%
* procedure, function calls 15%
* 100 statments are dynamically executed. The program is
* balanced with respect to the three aspects:
* - statements type
* - operand type (for simple data types)
* - operand access
* operand global, local, parameter, or constant.
*
* The combination of these three aspects is balanced only
* approximately.
*
* The program does not compute anything meaningful, but it
* is syntactically and semantically correct.
*
*
*/
#include <stdio.h>
#include <setsys.h>
/* Accuracy of timings controlled by next two lines */
/*#define LOOPS 50000 */ /*Use this for slow or 16 bit machines */
#define LOOPS 500000 /*Use the for faster machines */
/* Compiler dependent options */
#define ENUM /*Define if compiler has enum's */
#define STRUCTASSIGN 1 /*Define if compiler can assign structures*/
#define REG register
/* define only one of the next two defines */
#define TIME /*Use time(2) time function*/
/*#define TIMES /* Use times(2) time function */
#include <time.h>
/* define the granularity of your times(2) function (when used) */
/*#define HZ 50 /* times(2) returns 1/50 second (europe?)*/
#ifndef ATT3B
#define HZ 60 /* times (2) returns 1/60 second (most) */
#else
#define HZ 100 /* times (2) returns 1/1000 second (WECo)*/
#endif
char Version[] = "1.1";
#ifndef STRUCTASSIGN
#define structassign(d, s) memcpy(&(d), &(s), sizeof(d))
#else
#define structassign(d, s) d = s
#endif
#ifdef ENUM
typedef enum
{Ident1, Ident2, Ident3, Ident4, Ident5} Enumeration;
#else
#define Ident1 1
#define Ident2 2
#define Ident3 3
#define Ident4 4
#define Ident5 5
#define Enumeration int
#endif
#define OneToThirty int
#define OneToFifty int
#define CapitalLetter char
struct Record
{
struct Record *PtrComp;
Enumeration Discr;
Enumeration EnumComp;
OneToFifty IntComp;
char StringComp[30];
};
#define RecordType struct Record
#define RecordPtr RecordType *
#define boolean int
/* #define NULL 0 */
#define TRUE 1
#define FALSE 0
#ifndef REG
#define REG
#endif
extern Enumeration Func1();
extern boolean Func2();
#ifdef TIMES
#include <types.h>
#include <time.h>
#endif
double seconds ;
main()
{
Proc0();
exit(0);
}
/*
* Package 1
*/
int IntGlob;
boolean BoolGlob;
char Char1Glob;
char Char2Glob;
int Array1Glob[51];
int Array2Glob[51][51];
RecordPtr PtrGlb;
RecordPtr PtrGlbNext;
Proc0()
{
OneToFifty IntLoc1;
REG OneToFifty IntLoc2;
OneToFifty IntLoc3;
REG char CharLoc;
REG char CharIndex;
Enumeration EnumLoc;
char String1Loc[30];
char String2Loc[30];
extern char *malloc();
register unsigned int i ;
#ifdef TIME
time_t time();
time_t starttime;
time_t benchtime;
time_t nulltime;
starttime = clock();
for (i =0; i < LOOPS; ++i);
/* Computes overhead of looping */
nulltime = clock();
nulltime = nulltime - starttime;
#endif
#ifdef TIMES
time_t starttime;
time_t benchtime;
time_t nulltime;
struct tms tms;
times(&tms); starttime = tms.tms_utime;
for (i = 0; i < LOOPS; ++i);
times (&tms);
/* Computes overhead of looping */
nulltime = tms.tms_utime - starttime;
#endif
PtrGlbNext = (RecordPtr) malloc(sizeof(RecordType));
PtrGlb = (RecordPtr) malloc(sizeof(RecordType));
PtrGlb->PtrComp = PtrGlbNext;
PtrGlb->Discr = Ident1;
PtrGlb->EnumComp = Ident3;
PtrGlb->IntComp = 40;
strcpy(PtrGlb->StringComp, "DHRYSTONE PROGRAM, SOME STRING");
strcpy(String1Loc, "DHRYSTONE PROGRAMM 1'ST STRING");
Array2Glob[8][7] = 10;
/****************
- Start Timer -
****************/
#ifdef TIME
starttime = clock();
#endif
#ifdef TIMES
times(&tms); starttime = tms.tms_utime;
#endif
for (i = 0; i < LOOPS; ++i)
{
Proc5();
Proc4();
IntLoc1 = 2;
IntLoc2 = 3;
strcpy(String2Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
EnumLoc = Ident2;
BoolGlob = ! Func2(String1Loc, String2Loc);
while ( IntLoc1 < IntLoc2)
{
IntLoc3 = 5 * IntLoc1 - IntLoc2;
Proc7(IntLoc1, IntLoc2, &IntLoc3);
++IntLoc1;
}
Proc8(Array1Glob, Array2Glob, IntLoc1, IntLoc3);
Proc1(PtrGlb);
for (CharIndex = 'A' ; CharIndex <= Char2Glob;
++CharIndex)
if ( EnumLoc == Func1(CharIndex, 'C'))
Proc6(Ident1, &EnumLoc);
IntLoc3 = IntLoc2 * IntLoc1;
IntLoc2 = IntLoc3 / IntLoc1;
IntLoc2 = 7 * ( IntLoc3 - IntLoc2) - IntLoc1;
Proc2 ( &IntLoc1 );
}
/***************
- Stop Timer -
***************/
#ifdef TIME
benchtime = clock();
benchtime -= starttime;
benchtime -= nulltime;
seconds = (double)benchtime / (double)CLK_TCK;
printf ("Dhrystone(%s) time form %ld passes = %.2f\n",
Version, (long) LOOPS, seconds);
printf("This machine bnechmarks at %.2f dhrystones/second\n",
(double)((long) LOOPS) / seconds);
#endif
#ifdef TIMES
times(&tms);
benchtime = tms.tms_utime - starttime - nulltime;
printf("Dhrystone(%s) time for %ld passes = %ld\n",
Vsersion, (long) LOOPS, benchtime/HZ);
printf("This machine benchmarks at %ld dhrystones/second\n",
((long LOOPS) * HZ / benchtime);
#endif
}
Proc1(PtrParIn)
REG RecordPtr PtrParIn;
{
#define NextRecord (*(PtrParIn->PtrComp))
structassign(NextRecord, *PtrGlb);
PtrParIn->IntComp = 5;
NextRecord.IntComp = PtrParIn->IntComp;
NextRecord.PtrComp = PtrParIn->PtrComp;
Proc3(NextRecord.PtrComp);
if (NextRecord.Discr == Ident1 )
{
NextRecord.IntComp = 6;
Proc6(PtrParIn->EnumComp, &NextRecord.EnumComp);
NextRecord.PtrComp = PtrGlb->PtrComp;
Proc7(NextRecord.IntComp, 10, &NextRecord.IntComp);
}
else
structassign(*PtrParIn, NextRecord);
#undef NextRecord
}
Proc2(IntParIO)
OneToFifty *IntParIO;
{
REG OneToFifty IntLoc;
REG Enumeration EnumLoc;
IntLoc = *IntParIO + 10;
for (;;)
{
if (Char1Glob == 'A')
{
--IntLoc;
*IntParIO = IntLoc - IntGlob;
EnumLoc = Ident1;
}
if (EnumLoc == Ident1)
break;
}
}
Proc3 (PtrParOut)
RecordPtr *PtrParOut;
{
if (PtrGlb != NULL)
*PtrParOut = PtrGlb->PtrComp;
else
IntGlob = 100;
Proc7(10, IntGlob, &PtrGlb->IntComp);
}
Proc4()
{
REG boolean BoolLoc;
BoolLoc = Char1Glob == 'A';
BoolLoc |= BoolGlob;
Char2Glob = 'B';
}
Proc5()
{
Char1Glob ='A';
BoolGlob = FALSE;
}
extern boolean Func3();
Proc6 (EnumParIn, EnumParOut)
REG Enumeration EnumParIn;
REG Enumeration *EnumParOut;
{
*EnumParOut = EnumParIn;
if (! Func3(EnumParIn) )
*EnumParOut = Ident4;
switch (EnumParIn)
{
case Ident1: *EnumParOut = Ident1; break;
case Ident2: if ( IntGlob > 100)
*EnumParOut = Ident1;
else
*EnumParOut = Ident4;
break;
case Ident3: *EnumParOut = Ident2; break;
case Ident4: break;
case Ident5: *EnumParOut = Ident3;
}
}
Proc7(IntParI1, IntParI2, IntParOut)
OneToFifty IntParI1;
OneToFifty IntParI2;
OneToFifty *IntParOut;
{
REG OneToFifty IntLoc;
IntLoc = IntParI1 + 2;
*IntParOut = IntParI2 + IntLoc;
}
Proc8 (Array1Par, Array2Par, IntParI1, IntParI2)
int Array1Par[51];
int Array2Par[51][51];
OneToFifty IntParI1;
OneToFifty IntParI2;
{
REG OneToFifty IntLoc;
REG OneToFifty IntIndex;
IntLoc = IntParI1 + 5;
Array1Par[IntLoc] = IntParI2;
Array1Par[IntLoc+1] = Array1Par[IntLoc];
Array1Par[IntLoc+30] = IntLoc;
for ( IntIndex = IntLoc; IntIndex <= (IntLoc+1); ++IntIndex)
Array2Par[IntLoc][IntIndex] = IntLoc;
++Array2Par[IntLoc][IntLoc-1];
Array2Par[IntLoc+20][IntLoc] = Array1Par[IntLoc];
IntGlob = 5;
}
Enumeration Func1(CharPar1, CharPar2)
CapitalLetter CharPar1;
CapitalLetter CharPar2;
{
REG CapitalLetter CharLoc1;
REG CapitalLetter CharLoc2;
CharLoc1 = CharPar1;
CharLoc2 = CharLoc1;
if ( CharLoc2 != CharPar2)
return (Ident1);
else
return (Ident2);
}
boolean Func2 (StrParI1, StrParI2)
char StrParI1[30];
char StrParI2[30];
{
REG OneToThirty IntLoc;
REG CapitalLetter CharLoc;
IntLoc = 1;
while (IntLoc <= 1)
if ( Func1 (StrParI1[IntLoc], StrParI2[IntLoc+1]) == Ident1)
{
CharLoc = 'A';
++IntLoc;
}
if (CharLoc >= 'W' && CharLoc <= 'Z')
IntLoc = 7;
if (CharLoc == 'X')
return(TRUE);
else
{
if (strcmp (StrParI1, StrParI2) > 0)
{
IntLoc += 7;
return (TRUE);
}
else
return (FALSE);
}
}
boolean Func3(EnumParIn)
REG Enumeration EnumParIn;
{
REG Enumeration EnumLoc;
EnumLoc = EnumParIn;
if (EnumLoc == Ident3) return (TRUE);
return (FALSE);
}
#ifndef STRUCTASSIGN
memcpy (d, s, l)
register char *d;
register char *s;
register int l;
{
while (l--) *d++ = *s++;
}
#endif