home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 10
/
Fresh_Fish_10_2352.bin
/
new
/
dev
/
obero
/
oberon
/
demos
/
hennessy.mod
(
.txt
)
< prev
next >
Wrap
Oberon Text
|
1995-04-06
|
21KB
|
891 lines
Syntax10.Scn.Fnt
MODULE Hennessy;
(* This is a suite of benchmarks that are relatively short, both in program
size and execution time. It requires no input, and prints the execution
time for each program, using the system- dependent routine Getclock,
below, to find out the current CPU time. It does a rudimentary check to
make sure each program gets the right output. These programs were
gathered by John Hennessy and modified by Peter Nye.
Oberon: J.Templ 26.2.90 *)
IMPORT
Oberon, Texts, S := SYSTEM;
CONST
bubblebase = 1.61;
dnfbase = 3.5;
permbase = 1.75;
queensbase = 1.83;
towersbase = 2.39;
quickbase = 1.92;
intmmbase = 1.46;
treebase = 2.5;
mmbase = 0.0 (* 0.73 *);
fpmmbase = 2.92;
puzzlebase = 0.5;
fftbase = 0.0 (* 1.11 *);
fpfftbase = 4.44;
(* Towers *)
maxcells = 18;
stackrange = (*0..*) 3;
(* Intmm, Mm *)
rowsize = 40;
(* Puzzle *)
size = 511;
classmax = 3;
typemax = 12;
d = 8;
(* Bubble, Quick *)
sortelements = 5000;
srtelements = 500;
(* fft *)
fftsize = 256;
fftsize2 = 129;
(* Perm *)
permrange = (*0 ..*)10;
(* Towers *)
(* tree *)
node = POINTER TO nodeDesc;
nodeDesc = RECORD
left, right: node;
val: LONGINT;
END;
(* Towers
discsizrange = 1..maxcells;
cellcursor = 0..maxcells; *)
element = RECORD
discsize: LONGINT;
next: LONGINT;
END ;
(* emsgtype = packed array[1..15] of char;
(* Intmm, Mm *) (*
index = 1 .. rowsize; *)
intmatrix = ARRAY rowsize+1,rowsize+1 OF LONGINT;
realmatrix = ARRAY rowsize+1,rowsize+1 OF REAL;
(* Puzzle *) (*
piececlass = 0..classmax;
piecetype = 0..typemax;
position = 0..size;
(* Bubble, Quick *) (*
listsize = 0..sortelements;
sortarray = array [listsize] of integer;
(* FFT *)
complex = RECORD
rp, ip: REAL
END;
carray = ARRAY fftsize+1 OF complex ;
c2array = ARRAY fftsize2+1 OF complex ;
Proc = PROCEDURE;
fixed,floated: REAL;
(* global *)
seed: LONGINT;
(* Perm *)
permarray: ARRAY permrange+1 OF LONGINT;
pctr: LONGINT;
(* tree *)
tree: node;
(* Towers *)
stack: ARRAY stackrange+1 OF LONGINT;
cellspace: ARRAY maxcells+1 OF element;
freelist: LONGINT;
movesdone: LONGINT;
(* Intmm, Mm *)
ima, imb, imr: intmatrix;
rma, rmb, rmr: realmatrix;
(* Puzzle *)
piececount: ARRAY classmax+1 OF LONGINT;
class, piecemax: ARRAY typemax+1 OF LONGINT;
puzzl: ARRAY size+1 OF BOOLEAN;
p: ARRAY typemax+1, size+1 OF BOOLEAN;
kount: LONGINT;
(* Bubble, Quick *)
sortlist: ARRAY sortelements+1 OF LONGINT;
biggest, littlest,
top: LONGINT;
(* FFT *)
z, w: carray;
e: c2array;
zr, zi: REAL;
W: Texts.Writer;
(* global procedures *)
PROCEDURE Str*(s: ARRAY OF CHAR);
VAR i: INTEGER;
BEGIN
i:=0;
WHILE s[i] # 0X DO
IF s[i]="$" THEN Texts.WriteLn(W) ELSE Texts.Write(W, s[i]) END;
INC(i)
END;
Texts.Append(Oberon.Log, W.buf)
END Str;
PROCEDURE Getclock (): LONGINT;
BEGIN
RETURN Oberon.Time()
END Getclock;
PROCEDURE Initrand ();
BEGIN seed := 74755
END Initrand;
PROCEDURE Rand (): LONGINT;
BEGIN
seed := (seed * 1309 + 13849) MOD 65535;
RETURN (seed);
END Rand;
(* Permutation program, heavily recursive, written by Denny Brown. *)
PROCEDURE Swap (VAR a,b: LONGINT);
VAR t: LONGINT;
BEGIN t := a; a := b; b := t;
END Swap;
PROCEDURE Initialize ();
VAR i: LONGINT;
BEGIN i := 1;
WHILE i <= 7 DO
permarray[i] := i-1;
INC(i)
END
END Initialize;
PROCEDURE Permute (n: LONGINT);
VAR k: LONGINT;
BEGIN
pctr := pctr + 1;
IF ( n#1 ) THEN
Permute(n-1);
k := n-1;
WHILE k >= 1 DO
Swap(permarray[n], permarray[k]);
Permute(n-1);
Swap(permarray[n], permarray[k]);
DEC(k)
END
END
END Permute;
PROCEDURE *Perm ();
VAR i: LONGINT;
BEGIN
pctr := 0; i := 1;
WHILE i <= 5 DO
Initialize();
Permute(7);
INC(i)
END ;
IF ( pctr # 43300 ) THEN Str(" Error in Perm.$") END
END Perm;
(* Program to Solve the Towers of Hanoi *)
PROCEDURE Makenull (s: LONGINT);
BEGIN stack[s] := 0
END Makenull;
PROCEDURE Getelement (): LONGINT;
VAR temp: LONGINT;
BEGIN
IF ( freelist>0 ) THEN
temp := freelist;
freelist := cellspace[freelist].next;
ELSE
Str("out of space $")
END ;
RETURN (temp);
END Getelement;
PROCEDURE Push(i,s: LONGINT);
VAR localel: LONGINT; errorfound: BOOLEAN;
BEGIN
errorfound := FALSE;
IF ( stack[s] > 0 ) THEN
IF ( cellspace[stack[s]].discsize<=i ) THEN
errorfound := TRUE;
Str("disc size error$")
END
END ;
IF ( ~ errorfound ) THEN
localel := Getelement();
cellspace[localel].next := stack[s];
stack[s] := localel;
cellspace[localel].discsize := i
END
END Push;
PROCEDURE Init (s,n: LONGINT);
VAR discctr: LONGINT;
BEGIN
Makenull(s); discctr := n;
WHILE discctr >= 1 DO
Push(discctr,s);
DEC(discctr)
END
END Init;
PROCEDURE Pop (s: LONGINT): LONGINT;
VAR temp, temp1: LONGINT;
BEGIN
IF ( stack[s] > 0 ) THEN
temp1 := cellspace[stack[s]].discsize;
temp := cellspace[stack[s]].next;
cellspace[stack[s]].next := freelist;
freelist := stack[s];
stack[s] := temp;
RETURN (temp1)
ELSE
Str("nothing to pop $")
END
END Pop;
PROCEDURE Move (s1,s2: LONGINT);
BEGIN
Push(Pop(s1),s2);
movesdone := movesdone+1;
END Move;
PROCEDURE tower(i,j,k: LONGINT);
VAR other: LONGINT;
BEGIN
IF ( k=1 ) THEN
Move(i,j);
ELSE
other := 6-i-j;
tower(i,other,k-1);
Move(i,j);
tower(other,j,k-1)
END
END tower;
PROCEDURE *Towers ();
VAR i: LONGINT;
BEGIN i := 1;
WHILE i <= maxcells DO cellspace[i].next := i-1; INC(i) END ;
freelist := maxcells;
Init(1,14);
Makenull(2);
Makenull(3);
movesdone := 0;
tower(1,2,14);
IF ( movesdone # 16383 ) THEN Str(" Error in Towers.$") END
END Towers;
(* The eight queens problem, solved 50 times. *)
type
doubleboard = 2..16;
doublenorm = -7..7;
boardrange = 1..8;
aarray = array [boardrange] of boolean;
barray = array [doubleboard] of boolean;
carray = array [doublenorm] of boolean;
xarray = array [boardrange] of boardrange;
PROCEDURE Try(i: LONGINT; VAR q: BOOLEAN; VAR a, b, c: ARRAY OF BOOLEAN; VAR x: ARRAY OF LONGINT);
VAR j: LONGINT;
BEGIN
j := 0;
q := FALSE;
WHILE (~q) & (j # 8) DO
j := j + 1;
q := FALSE;
IF b[j] & a[i+j] & c[i-j+7] THEN
x[i] := j;
b[j] := FALSE;
a[i+j] := FALSE;
c[i-j+7] := FALSE;
IF i < 8 THEN
Try(i+1,q,a,b,c,x);
IF ~q THEN
b[j] := TRUE;
a[i+j] := TRUE;
c[i-j+7] := TRUE
END
ELSE q := TRUE
END
END
END
END Try;
PROCEDURE Doit ();
VAR i: LONGINT; q: BOOLEAN;
a: ARRAY 9 OF BOOLEAN;
b: ARRAY 17 OF BOOLEAN;
c: ARRAY 15 OF BOOLEAN;
x: ARRAY 9 OF LONGINT;
BEGIN
i := 0 - 7;
WHILE i <= 16 DO
IF (i >= 1) & (i <= 8) THEN a[i] := TRUE END ;
IF i >= 2 THEN b[i] := TRUE END ;
IF i <= 7 THEN c[i+7] := TRUE END ;
i := i + 1;
END ;
Try(1, q, b, a, c, x);
IF ( ~ q ) THEN Str(" Error in Queens.$") END
END Doit;
PROCEDURE *Queens ();
VAR i: LONGINT;
BEGIN i := 1;
WHILE i <= 50 DO Doit(); INC(i) END
END Queens;
(* Multiplies two integer matrices. *)
PROCEDURE Initmatrix (VAR m: intmatrix);
VAR temp, i, j: LONGINT;
BEGIN i := 1;
WHILE i <= rowsize DO
j := 1;
WHILE j <= rowsize DO
temp := Rand();
m[i][j] := temp - (temp DIV 120)*120 - 60;
INC(j)
END ;
INC(i)
END
END Initmatrix;
PROCEDURE Innerproduct(VAR result: LONGINT; VAR a,b: intmatrix; row,column: LONGINT);
VAR i: LONGINT;
(* computes the inner product of A[row,*] and B[*,column] *)
BEGIN
result := 0; i := 1;
WHILE i <= rowsize DO result := result+a[row][i]*b[i][column]; INC(i) END
END Innerproduct;
PROCEDURE *Intmm ();
VAR i, j: LONGINT;
BEGIN
Initrand();
Initmatrix (ima);
Initmatrix (imb);
i := 1;
WHILE i <= rowsize DO j := 1;
WHILE j <= rowsize DO Innerproduct(imr[i][j],ima,imb,i,j); INC(j) END ;
INC(i)
END Intmm;
(* Multiplies two real matrices. *)
PROCEDURE rInitmatrix (VAR m: realmatrix);
VAR temp, i, j: LONGINT;
BEGIN i := 1;
WHILE i <= rowsize DO j := 1;
WHILE j <= rowsize DO
temp