home *** CD-ROM | disk | FTP | other *** search
- -- A000094.ADA "Henessy" benchmarks
- --
- -- modified to use CPU_TIME_CLOCK rather than CALENDAR.CLOCK for PIWG
- -- ( Editorial note: These are unchanged by PIWG other than the the use of
- -- CPU time rather than wall time. These procedures are for comparison
- -- purposes. Many came from other languages and are used for comparing
- -- Ada to other languages. Most of these procedures would be considered
- -- poor Ada programming. The matrix multiply is also a poor numerical
- -- method. )
- --
- -- 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 Henessy and modified by Peter Nye.
-
- -- Ada version translated from Pascal
- -- 11/15/85 by Mitchell Gart, Alsys Inc.
-
- with TEXT_IO, CPU_TIME_CLOCK, DURATION_IO;
-
- procedure A000094 is
-
- -- Global variables:
- TIMER: DURATION ;
- XTIMES: ARRAY(1..11) OF DURATION;
- SORTELEMENTS: constant := 5000;
- type LISTSIZE is range 0..SORTELEMENTS;
- RANDARRAY: ARRAY (LISTSIZE) OF INTEGER;
- type LONG_INTEGER is range -2**30 .. 2**30 ;
- SEED: LONG_INTEGER;
-
- -- Shared by Bubble and Quick
- type sortarray is array (listsize) of integer;
- sortlist: sortarray;
- biggest, littlest: integer;
- top: listsize;
-
-
- -- global procedures
-
- -- Getclock was replaced by CPU_TIME_CLOCK
- -- function Getclock return CALENDAR.TIME renames CALENDAR.CLOCK;
-
-
- procedure Initrand is
- begin
- seed := 74755;
- end;
-
- function Rand return integer is
- begin
- seed := (seed * 1309 + 13849) mod 32767;
- return INTEGER(SEED);
- end;
-
-
-
- generic
- type ELEM is private;
- with function CVT(VAL: INTEGER) return ELEM;
- with function "+"(LEFT, RIGHT: ELEM) return ELEM is <>;
- with function "*"(LEFT, RIGHT: ELEM) return ELEM is <>;
- procedure MATRIX_MULT;
-
- -- Integer and real matrix multiplication, programmed with generics:
-
- procedure MATRIX_MULT is
- rowsize: constant := 40;
- type index is range 1 .. rowsize;
- type matrix is array (index,index) of ELEM;
- ima, imb, imr: matrix;
-
- procedure Initmatrix (m: out matrix) is
- K: LISTSIZE;
- begin
- K := 0;
- for I in INDEX'FIRST..INDEX'LAST loop
- for J in INDEX'FIRST..INDEX'LAST loop
- M(I,J) := CVT(RANDARRAY(K) mod 120 - 60);
- K := K+1;
- end loop;
- end loop;
- end INITMATRIX;
-
- procedure Innerproduct (
- RESULT: out ELEM;
- A,B: in MATRIX;
- ROW,COLUMN: in INDEX ) is
- -- computes the inner product of A(row, and B--,column)
- RES : ELEM := CVT(0);
- begin
- for I in INDEX'FIRST..INDEX'LAST loop
- RES := RES + A(ROW,I)*B(I,COLUMN);
- end loop;
- RESULT := RES;
- end INNERPRODUCT;
-
- begin -- MATRIX_MULT
- INITMATRIX (IMA);
- INITMATRIX (IMB);
- for I in INDEX'FIRST..INDEX'LAST loop
- for J in INDEX'FIRST..INDEX'LAST loop
- INNERPRODUCT(IMR(I,J),IMA,IMB,I,J);
- end loop;
- end loop;
- end MATRIX_MULT;
-
- -- Having to specify these conversion routines is sort of a pain.
- -- At least they are only called during matrix initialization,
- -- not during the product loop.
-
- function INT_CVT(I: INTEGER) return INTEGER is
- begin
- return I;
- end INT_CVT;
-
- function FLOAT_CVT(I: INTEGER) return FLOAT is
- begin
- return FLOAT(I);
- end FLOAT_CVT;
-
- -- Here are the instantiations. "*" and "+" are implied parameters.
-
- procedure Intmm is new MATRIX_MULT(INTEGER, INT_CVT);
-
- procedure mm is new MATRIX_MULT(FLOAT, FLOAT_CVT);
-
-
-
- procedure Puzzle is
-
- -- A compute-bound program from Forest Baskett.
-
- size: constant := 511;
- classmax: constant := 3;
- typemax: constant := 12;
- d: constant := 8;
-
- type piececlass is range 0..classmax;
- type piecetype is range 0..typemax;
- type position is range 0..size;
- type piecerange is range 0..13;
-
- piececount: array (piececlass) of piecerange;
- class: array (piecetype) of piececlass;
- piecemax: array (piecetype) of position;
- puzzl: array (position) of boolean;
- p: array (piecetype, position) of boolean;
- m,n: position;
- kount: integer;
-
- function Fit (i : piecetype; j : position) return boolean is
-
- k,m : position;
-
- begin
- for k in 0 .. piecemax(i) loop
- if p(i,k) and then puzzl(j+k) then return false; end if;
- end loop;
- return true;
- end;
-
- function Place (i : piecetype; j : position) return position is
- begin
- for K in 0 .. PIECEMAX(I) loop
- if p(i,k) then puzzl(j+k) := true; end if;
- end loop;
- piececount(class(i)) := piececount(class(i)) - 1;
- for K in J .. SIZE loop
- if not PUZZL(K) then
- return K;
- end if;
- end loop;
- return 0;
- end;
-
- procedure Remove (i : piecetype; j : position) is
- begin
- for K in 0 .. PIECEMAX(I) loop
- if P(I,K) then PUZZL(J+K) := FALSE; end if;
- end loop;
- PIECECOUNT(CLASS(I)) := PIECECOUNT(CLASS(I)) + 1;
- end REMOVE;
-
- function Trial (J : position) return boolean is
- k : position;
- begin
- kount := kount + 1;
- for I in PIECETYPE'FIRST..PIECETYPE'LAST loop
- if PIECECOUNT(CLASS(I)) /= 0 then
- if Fit (i, j) then
- k := Place (i, j);
- if Trial(k) OR (k = 0) then
- return TRUE;
- else
- Remove (i, j);
- end if;
- end if;
- end if;
- end loop;
- return FALSE;
- end TRIAL;
-
- begin -- PUZZLE
-
- for m in POSITION'FIRST..POSITION'LAST loop puzzl(m) := true; end loop;
- for i in 1 .. 5 loop for j in 1 .. 5 loop for k in 1 .. 5 loop
- puzzl(POSITION(i+d*(j+d*k))) := false;
- end loop; end loop; end loop;
- for i in PIECETYPE'FIRST..PIECETYPE'LAST loop
- for m in POSITION'FIRST..POSITION'LAST loop
- p(i, m) := false;
- end loop;
- end loop;
- for i in 0..3 loop for j in 0 .. 1 loop for k in 0 .. 0 loop
- p(0,POSITION(i+d*(j+d*k))) := true;
- end loop; end loop;
- end loop;
- class(0) := 0;
- piecemax(0) := 3+d*1+d*d*0;
- for i in 0 .. 1 loop for j in 0 .. 0 loop for k in 0 .. 3 loop
- p(1,POSITION(i+d*(j+d*k))) := true;
- end loop; end loop; end loop;
- class(1) := 0;
- piecemax(1) := 1+d*0+d*d*3;
- for i in 0 .. 0 loop for j in 0 .. 3 loop for k in 0 .. 1 loop
- p(2,POSITION(i+d*(j+d*k))) := true;
- end loop; end loop; end loop;
- class(2) := 0;
- piecemax(2) := 0+d*3+d*d*1;
- for i in 0 .. 1 loop for j in 0 .. 3 loop for k in 0 .. 0 loop
- p(3,POSITION(i+d*(j+d*k))) := true;
- end loop; end loop; end loop;
- class(3) := 0;
- piecemax(3) := 1+d*3+d*d*0;
- for i in 0 .. 3 loop for j in 0 .. 0 loop for k in 0 .. 1 loop
- p(4,POSITION(i+d*(j+d*k))) := true;
- end loop; end loop; end loop;
- class(4) := 0;
- piecemax(4) := 3+d*0+d*d*1;
- for i in 0 .. 0 loop for j in 0 .. 1 loop for k in 0 .. 3 loop
- p(5,POSITION(i+d*(j+d*k))) := true;
- end loop; end loop; end loop;
- class(5) := 0;
- piecemax(5) := 0+d*1+d*d*3;
- for i in 0 .. 2 loop for j in 0 .. 0 loop for k in 0 .. 0 loop
- p(6,POSITION(i+d*(j+d*k))) := true;
- end loop; end loop; end loop;
- class(6) := 1;
- piecemax(6) := 2+d*0+d*d*0;
- for i in 0 .. 0 loop for j in 0 .. 2 loop for k in 0 .. 0 loop
- p(7,POSITION(i+d*(j+d*k))) := true;
- end loop; end loop; end loop;
- class(7) := 1;
- piecemax(7) := 0+d*2+d*d*0;
- for i in 0 .. 0 loop for j in 0 .. 0 loop for k in 0 .. 2 loop
- p(8,POSITION(i+d*(j+d*k))) := true;
- end loop; end loop; end loop;
- class(8) := 1;
- piecemax(8) := 0+d*0+d*d*2;
- for i in 0 .. 1 loop for j in 0 .. 1 loop for k in 0 .. 0 loop
- p(9,POSITION(i+d*(j+d*k))) := true;
- end loop; end loop; end loop;
- class(9) := 2;
- piecemax(9) := 1+d*1+d*d*0;
- for i in 0 .. 1 loop for j in 0 .. 0 loop for k in 0 .. 1 loop
- p(10,POSITION(i+d*(j+d*k))) := true;
- end loop; end loop; end loop;
- class(10) := 2;
- piecemax(10) := 1+d*0+d*d*1;
- for i in 0 .. 0 loop for j in 0 .. 1 loop for k in 0 .. 1 loop
- p(11,POSITION(i+d*(j+d*k))) := true;
- end loop; end loop; end loop;
- class(11) := 2;
- piecemax(11) := 0+d*1+d*d*1;
- for i in 0 .. 1 loop for j in 0 .. 1 loop for k in 0 .. 1 loop
- p(12,POSITION(i+d*(j+d*k))) := true;
- end loop; end loop; end loop;
- class(12) := 3;
- piecemax(12) := 1+d*1+d*d*1;
- piececount(0) := 13;
- piececount(1) := 3;
- piececount(2) := 1;
- piececount(3) := 1;
- m := 1+d*(1+d*1);
- kount := 0;
- if Fit(0, m) then
- n := Place(0, m);
- else
- TEXT_IO.PUT_LINE("Error1 in Puzzle");
- end if;
- if NOT Trial(n) then
- TEXT_IO.PUT_LINE("Error2 in Puzzle.");
- elsif kount /= 2005 then
- TEXT_IO.PUT_LINE("Error3 in Puzzle.");
- end if;
- end PUZZLE;
-
-
-
- procedure TREES is
-
- -- Sorts an array using treesort
-
- type NODE;
- type NODEPTR is access NODE;
- type NODE is record
- LEFT,
- RIGHT: NODEPTR;
- VAL: INTEGER;
- end record;
-
- -- tree
- TREE: NODEPTR;
-
- procedure INITARR is
- begin
- BIGGEST := 0; LITTLEST := 0;
- for I in LISTSIZE'FIRST .. LISTSIZE'LAST loop
- SORTLIST(I) := (RANDARRAY(I) mod 10000) - 5000;
- if SORTLIST(I) > BIGGEST then
- BIGGEST := SORTLIST(I);
- elsif SORTLIST(I) < LITTLEST then
- LITTLEST := SORTLIST(I);
- end if;
- end loop;
- end INITARR;
-
- procedure INSERT(N: INTEGER; T: in out NODEPTR) is
- -- insert n into tree
-
- procedure CreateNode(t: in out nodeptr; n: in integer) is
- begin
- T := new NODE;
- T.LEFT := null;
- T.RIGHT := null;
- T.VAL := N;
- end CREATENODE;
-
- begin
- if N>T.VAL then
- if T.LEFT=NULL then
- CREATENODE(T.LEFT, N);
- else
- INSERT(N, T.LEFT);
- end if;
- elsif N<T.VAL then
- if T.RIGHT=null then
- CREATENODE(T.RIGHT,N);
- else
- INSERT(N,T.RIGHT);
- end if;
- end if;
- end INSERT;
-
-
- function CHECKTREE(P: NODEPTR) return BOOLEAN is
- -- check by inorder traversal
- RESULT: BOOLEAN;
- begin
- RESULT := TRUE;
- if P.LEFT/=null then
- if P.LEFT.VAL <= P.VAL then
- RESULT:=FALSE;
- else
- RESULT := CHECKTREE(P.LEFT) and RESULT;
- end if;
- end if;
- if P.RIGHT/=null then
- if P.RIGHT.VAL >= P.VAL then
- RESULT := FALSE;
- else
- RESULT := CHECKTREE(P.RIGHT) and RESULT;
- end if;
- end if;
- return RESULT;
- end CHECKTREE;
-
- begin -- TREES
-
- INITARR;
- TREE := new NODE;
- TREE.LEFT := null; TREE.RIGHT := null; TREE.VAL:=SORTLIST(1);
- for I in 2 .. SORTELEMENTS loop
- INSERT(SORTLIST(LISTSIZE(I)),TREE);
- end loop;
- if not CHECKTREE(TREE) then
- TEXT_IO.PUT(" Error in Tree.");
- end if;
-
- end TREES;
-
-
-
- procedure Perm is
- -- Permutation program, heavily recursive, written by Denny Brown.
- type permrange is range 0 .. 10;
- permarray: array (permrange) of permrange;
- pctr: long_integer;
- i: integer;
-
- procedure Swap(a, b : in permrange) is
- t : permrange;
- begin
- t := permarray(a);
- permarray(a) := permarray(b);
- permarray(b) := t;
- end;
-
- procedure Initialize is
- begin
- for i in 1 .. 7 loop
- permarray(permrange(i)) := permrange(i-1);
- end loop;
- end;
-
- procedure Permute(n : permrange) is
- begin
- pctr := pctr + 1;
- if n /= 1 then
- Permute(n-1);
- for k in reverse 1..n-1 loop
- Swap(n, k);
- Permute(n-1);
- Swap(n, k);
- end loop;
- end if;
- end permute;
-
- begin -- Perm
- pctr := 0;
- for i in 1 .. 5 loop
- Initialize;
- Permute(7);
- end loop;
- if pctr /= 43300 then
- TEXT_IO.PUT_LINE(" Error in Perm.");
- end if;
- end Perm;
-
-
-
- procedure Towers is
-
- -- Program to Solve the Towers of Hanoi
- towersbase: constant := 2.39;
- maxcells: constant := 18;
- type discsizrange is range 1..maxcells;
- type stackrange is range 1..3;
- type cellcursor is range 0..maxcells;
- type element is record
- discsize:discsizrange;
- next:cellcursor;
- end record;
-
- stack: array(stackrange) of cellcursor;
- cellspace: array(1..maxcells) of element;
- cfreelist: cellcursor;
- movesdone: integer;
- -- Freelist: integer;
-
- procedure Error (emsg: string) is
- begin
- TEXT_IO.PUT("Error in Towers: ");
- TEXT_IO.PUT_LINE(EMSG);
- end;
-
- procedure Makenull (s:stackrange) is
- begin
- stack(s):=0;
- end;
-
- function Getelement return cellcursor is
- RESULT: CELLCURSOR;
- begin
- if cfreelist>0 then
- RESULT := cfreelist;
- cfreelist:=cellspace(integer(cfreelist)).next;
- return RESULT;
- else
- Error("out of space ");
- end if;
- end getelement;
-
- procedure Push(i:discsizrange;s:stackrange) is
- errorfound:boolean;
- localel:cellcursor;
- begin
- errorfound:=false;
- if stack(s) > 0 then
- if cellspace(integer(stack(s))).discsize<=i then
- errorfound:=true;
- Error("disc size error");
- end if;
- end if;
- if NOT errorfound then
- localel:=Getelement;
- cellspace(integer(localel)).next:=stack(s);
- stack(s):=localel;
- cellspace(integer(localel)).discsize:=i;
- end if;
- end PUSH;
-
- procedure Init (s:stackrange;n:discsizrange) is
- discctr:discsizrange;
- begin
- Makenull(s);
- for discctr in reverse 1..n loop
- Push(discctr,s);
- end loop;
- end;
-
- function Pop (s:stackrange) return discsizrange is
- temp: cellcursor;
- result: discsizrange;
- begin
- if stack(s) > 0 then
- result := cellspace(integer(stack(s))).discsize;
- temp:=cellspace(integer(stack(s))).next;
- cellspace(integer(stack(s))).next:=cfreelist;
- cfreelist:=stack(s);
- stack(s):=temp;
- return result;
- else
- Error("nothing to pop ");
- end if;
- end pop;
-
- procedure Move (s1,s2:stackrange) is
- begin
- Push(Pop(s1),s2);
- movesdone:=movesdone+1;
- end;
-
- procedure Tower(i,j,k:integer) is
- other:integer;
- begin
- if k=1 then
- Move(stackrange(i),stackrange(j));
- else
- other:=6-i-j;
- Tower(i,other,k-1);
- Move(stackrange(i),stackrange(j));
- Tower(other,j,k-1);
- end if;
- end tower;
-
-
- begin -- Towers
- for I in 1..MAXCELLS loop
- cellspace(integer(I)).NEXT := cellcursor(I - 1);
- end loop;
- cfreelist:=maxcells;
- Init(1,14);
- Makenull(2);
- Makenull(3);
- movesdone:=0;
- Tower(1,2,14);
- if movesdone /= 16383 then
- TEXT_IO.PUT_LINE("Error in Towers.");
- end if;
- end Towers;
-
-
-
- procedure Queens is
-
- -- The eight queens problem, solved 50 times.
-
- i: integer;
-
- procedure Doit is
-
- subtype doubleboard is integer range 2..16;
- subtype doublenorm is integer range -7..7;
- subtype boardrange is integer range 1..8;
- type aarray is array (boardrange) of boolean;
- type barray is array (doubleboard) of boolean;
- type carray is array (doublenorm) of boolean;
- type xarray is array (boardrange) of boardrange;
-
- i: integer;
- q: boolean;
- a: aarray;
- b: barray;
- c: carray;
- x: xarray;
-
- procedure Try (
- i : in integer;
- q : in out boolean;
- a : in out barray;
- b : in out aarray) is
-
- j : integer;
-
- begin
- j := 0;
- q := false;
- while (not Q) and (J /= 8) loop
- j := j + 1;
- q := false;
- if B(J) and A(I+J) and C(I-J) then
- x(i) := j;
- b(j) := false;
- a(i+j) := false;
- c(i-j) := false;
- if i < 8 then
- Try(i+1,q,a,b);
- if NOT q then
- b(j) := true;
- a(i+j) := true;
- c(i-j) := true;
- end if;
- else
- q := true;
- end if;
- end if;
- end loop;
- end TRY;
-
- begin -- Doit
- i := 0 - 7;
- while I <= 16 loop
- if (I >= 1) and (I <= 8) then A(I) := TRUE; end if;
- if i >= 2 then B(I) := TRUE; end if;
- if i <= 7 then c(i) := true; end if;
- i := i + 1;
- end loop;
-
- Try(1, q, b, a);
- if not Q then
- TEXT_IO.PUT_LINE(" Error in Queens.");
- end if;
- end DOIT;
-
- begin -- Queens
- for i in 1 .. 50 loop
- Doit;
- end loop;
- end QUEENS;
-
-
-
- procedure Quick is
-
- -- Sorts an array using quicksort
-
- procedure INITARR is
- begin
- BIGGEST := -6500; LITTLEST := 6500;
- for I in 1 .. SORTELEMENTS loop
- SORTLIST(LISTSIZE(I)) := (RANDARRAY(LISTSIZE(I)) mod 10000) - 5000;
- if SORTLIST(LISTSIZE(I)) > BIGGEST then
- BIGGEST := SORTLIST(LISTSIZE(I));
- elsif SORTLIST(LISTSIZE(I)) < LITTLEST then
- LITTLEST := SORTLIST(LISTSIZE(I));
- end if;
- end loop;
- end INITARR;
-
- procedure QUICKSORT(A: in out SORTARRAY; L,R: LISTSIZE) is
- -- quicksort the array A from start to finish
- I,J: INTEGER;
- X,W: INTEGER;
- begin
- I:=INTEGER(L); J:=INTEGER(R);
- X:=A((L+R)/2);
- loop
- while A(LISTSIZE(I))<X loop I := I+1; end loop;
- while X<A(LISTSIZE(J)) loop J := J-1; end loop;
- if I<=J then
- W := A(LISTSIZE(I));
- A(LISTSIZE(I)) := A(LISTSIZE(J));
- A(LISTSIZE(J)) := W;
- I := i+1;
- J:= J-1;
- end if;
- exit when I > J;
- end loop;
- if L <LISTSIZE(J) then QUICKSORT(A,L,LISTSIZE(J)); end if;
- if LISTSIZE(I)<R then QUICKSORT(A,LISTSIZE(I),R); end if;
- end QUICKSORT;
-
- begin -- QUICK
- INITARR;
- QUICKSORT(SORTLIST, 1, SORTELEMENTS);
- if (SORTLIST(1) /= LITTLEST) or (SORTLIST(SORTELEMENTS) /= BIGGEST) then
- TEXT_IO.PUT(" Error in Quick.");
- end if;
- end QUICK;
-
-
-
-
- procedure Bubble is
-
- -- Sorts an array using bubblesort
-
- J: INTEGER;
- I, TOP: LISTSIZE;
- LIMIT: constant LISTSIZE := SORTELEMENTS/10;
-
- procedure INITARR is
- I: LISTSIZE;
- begin
- BIGGEST := 0; LITTLEST := 0;
- for I in 1 .. LISTSIZE'(SORTELEMENTS) loop
- SORTLIST(I) := (RANDARRAY(I) mod 10000) - 5000;
- if SORTLIST(I) > BIGGEST then
- BIGGEST := SORTLIST(I);
- elsif SORTLIST(I) < LITTLEST then
- LITTLEST := SORTLIST(I);
- end if;
- end loop;
- end INITARR;
-
- begin -- BUBBLE
- INITARR;
- TOP := LIMIT;
- while TOP>1 loop
- I:=1;
- while I<TOP loop
- if SORTLIST(I) > SORTLIST(I+1) then
- J := SORTLIST(I);
- SORTLIST(I) := SORTLIST(I+1);
- SORTLIST(I+1) := J;
- end if;
- I:=I+1;
- end loop;
- TOP:=TOP-1;
- end loop;
- for I in 2 .. LIMIT loop
- if (SORTLIST(I-1) > SORTLIST(I)) then
- TEXT_IO.PUT("Error3 in Bubble.");
- end if;
- end loop;
- end BUBBLE;
-
-
-
- procedure OSCAR is
-
- -- fft
-
- FFTSIZE: constant := 256 ;
- FFTSIZE2: constant := 129 ;
-
- type COMPLEX is record
- rp,
- ip: FLOAT;
- end record;
- type CARRAY is array (1..FFTSIZE) of COMPLEX ;
- type C2ARRAY is array (1..FFTSIZE2) of COMPLEX ;
-
- Z, W : CARRAY ;
- E : C2ARRAY ;
- ZR, ZI : FLOAT;
-
- function COS (X: FLOAT) return FLOAT is
- -- computes cos of x (x in radians) by an expansion
- type T is range 2..10;
- I: T;
- RESULT,POWER: FLOAT;
- FACTOR: LONG_INTEGER;
- begin
- RESULT := 1.0; FACTOR := 1; POWER := X;
- for I in 2 .. 10 loop
- FACTOR := FACTOR * LONG_INTEGER(I); POWER := POWER*X;
- if (I mod 2) = 0 then
- if (i mod 4) = 0 then
- result := result + power/FLOAT(FACTOR);
- else
- result := result - power/FLOAT(FACTOR);
- end if;
- end if;
- end loop;
- return RESULT;
- end;
-
- function MIN0( ARG1, ARG2 : INTEGER) return INTEGER is
- begin
- if ARG1 < ARG2 then
- return ARG1;
- else
- return ARG2;
- end if;
- end MIN0;
-
- procedure UNIFORM11( IY: in out LONG_INTEGER;
- YFL: out FLOAT) is
- begin
- IY := (4855*IY + 1731) mod 8192;
- YFL := FLOAT(IY)/8192.0;
- end UNIFORM11;
-
- procedure EXPTAB(N: INTEGER;
- E: in out C2ARRAY) is
-
- H: array (1..25) of FLOAT ;
- I, J, K, L, M : INTEGER;
- THETA, DIVISOR : FLOAT;
-
- begin -- exptab
- THETA := 3.1415926536;
- DIVISOR := 4.0;
- for I in 1 .. 25 loop
- H(I) := 1.0/(2.0*COS( THETA/DIVISOR ));
- DIVISOR := DIVISOR + DIVISOR;
- end loop;
-
- M := N / 2 ;
- L := M / 2 ;
- J := 1 ;
- E(1).RP := 1.0 ;
- E(1).IP := 0.0;
- E(L+1).RP := 0.0;
- E(L+1).IP := 1.0 ;
- E(M+1).RP := -1.0 ;
- E(M+1).IP := 0.0 ;
-
- loop
- I := L / 2 ;
- K := I ;
-
- loop
- E(K+1).RP := H(J)*(E(K+I+1).RP+E(K-I+1).RP) ;
- E(K+1).IP := H(J)*(E(K+I+1).IP+E(K-I+1).IP) ;
- K := K+L ;
- exit when K > M ;
- end loop;
-
- J := MIN0( J+1, 25);
- L := I ;
- exit when L <= 1 ;
- end loop;
-
- end EXPTAB;
-
- procedure FFT( N: in INTEGER ;
- Z, W: in out CARRAY ;
- E: in C2ARRAY ;
- SQRINV: in FLOAT) is
-
- I, J, K, L, M, INDEX: INTEGER ;
-
- begin
- m := n / 2 ;
- l := 1 ;
-
- loop
- k := 0 ;
- j := l ;
- i := 1 ;
-
- loop
-
- loop
- W(I+K).RP := Z(I).RP+Z(M+I).RP ;
- W(I+K).IP := Z(I).IP+Z(M+I).IP ;
- W(I+J).RP := E(K+1).RP*(Z(I).RP-Z(I+M).RP)
- -E(K+1).IP*(Z(I).IP-Z(I+M).IP) ;
- W(I+J).IP := E(K+1).RP*(Z(I).IP-Z(I+M).IP)
- +E(K+1).IP*(Z(I).RP-Z(I+M).RP) ;
- I := I+1 ;
- exit when I > J ;
- end loop;
-
- K := J ;
- J := K+L ;
- exit when J > M ;
- end loop;
-
- -- Z := W;
- INDEX := 1;
- loop
- Z(INDEX) := W(INDEX);
- INDEX := INDEX+1;
- exit when INDEX > N;
- end loop;
- L := L+L ;
- exit when l > m ;
- end loop;
-
- for I in 1 .. N loop
- Z(I).RP := SQRINV*Z(I).RP ;
- Z(I).IP := -SQRINV*Z(I).IP;
- end loop;
- end FFT;
-
- begin -- oscar
-
- EXPTAB(FFTSIZE,E) ;
- SEED := 5767 ;
- for I in 1 .. FFTSIZE loop
- UNIFORM11( SEED, ZR );
- UNIFORM11( SEED, ZI );
- Z(I).RP := 20.0*ZR - 10.0;
- Z(I).IP := 20.0*ZI - 10.0;
- end loop;
-
- for I in 1 .. 20 loop
- FFT(FFTSIZE,Z,W,E,0.0625) ;
- -- Printcomplex( 6, 99, z, 1, 256, 17 );
- end loop;
-
- end OSCAR;
-
-
-
- procedure ackerman is
- -- Ackerman function Ack(3,6) run 10 times:
- x : integer;
- function ack (m, n: integer) return integer is
- begin
- if m = 0 then
- return n + 1;
- elsif n = 0 then
- return ack (m - 1, 1);
- else
- return ack (m - 1, ack (m, n - 1));
- end if;
- end;
- begin
- for i in 1 .. 10 loop
- x := ack (3, 6);
- end loop;
- end ackerman;
-
-
-
- begin -- BENCH A00094
- INITRAND;
- for I in 1..SORTELEMENTS loop
- RANDARRAY(LISTSIZE(I)) := RAND;
- end loop;
- TEXT_IO.PUT_LINE("A000094");
- TEXT_IO.PUT(" Perm");timer := CPU_TIME_CLOCK;
- Perm; xtimes(1) := CPU_TIME_CLOCK-timer;
- TEXT_IO.PUT(" Towers");timer := CPU_TIME_CLOCK;
- Towers; xtimes(2) := CPU_TIME_CLOCK-timer;
- TEXT_IO.PUT(" Queens");timer := CPU_TIME_CLOCK;
- Queens; xtimes(3) := CPU_TIME_CLOCK-timer;
- TEXT_IO.PUT(" Intmm");timer := CPU_TIME_CLOCK;
- Intmm; xtimes(4) := CPU_TIME_CLOCK-timer;
- TEXT_IO.PUT(" Mm");timer := CPU_TIME_CLOCK;
- Mm; xtimes(5) := CPU_TIME_CLOCK-timer;
- TEXT_IO.PUT(" Puzzle");timer := CPU_TIME_CLOCK;
- Puzzle; xtimes(6) := CPU_TIME_CLOCK-timer;
- TEXT_IO.PUT(" Quick");timer := CPU_TIME_CLOCK;
- Quick; xtimes(7) := CPU_TIME_CLOCK-timer;
- TEXT_IO.PUT(" Bubble");timer := CPU_TIME_CLOCK;
- Bubble; xtimes(8) := CPU_TIME_CLOCK-timer;
- TEXT_IO.PUT(" Tree");timer := CPU_TIME_CLOCK;
- Trees; xtimes(9) := CPU_TIME_CLOCK-timer;
- TEXT_IO.PUT(" FFT");timer := CPU_TIME_CLOCK;
- Oscar; xtimes(10):= CPU_TIME_CLOCK-timer;
- TEXT_IO.PUT(" Ack");timer := CPU_TIME_CLOCK;
- Ackerman;xtimes(11):= CPU_TIME_CLOCK-timer;
- TEXT_IO.NEW_LINE;
- for I in 1..11 loop
- DURATION_IO.PUT(XTIMES(I), FORE=>4, AFT=>2, EXP=>0);
- end loop;
- TEXT_IO.NEW_LINE;
-
- end A000094;
-