home *** CD-ROM | disk | FTP | other *** search
/ Programmer's ROM - The Computer Language Library / programmersrom.iso / ada / piwg / a000092.ada < prev    next >
Encoding:
Text File  |  1988-05-03  |  13.0 KB  |  343 lines

  1. -- Ada version of Whetstone Benchmark Program
  2. -- This must be edited to "with" the compiler suppliers math routines
  3. --  SIN, COS, ATAN, SQRT, EXP and LOG
  4. --  These results may be interesting to compare to Z000093 that uses
  5. --  a physically included, all Ada set of math routines
  6.  
  7.  
  8. --------------------------------------------------------------------------
  9. --                                                                      --
  10. --     WHETADA.ADA    distributed as A000092.ADA                        --
  11. --                                                                      --
  12. --   Ada version of the Whetstone Benchmark Program.                    --
  13. --   Reference: "Computer Journal" February 1976, pages 43-49           --
  14. --              for description of benchmark and ALGOL60 version.       --
  15. -- Note: Procedure POUT is omitted.                                     --
  16. --                                                                      --
  17. -- From Timing Studies using a synthetic Whetstone Benchmark            --
  18. --      by Sam Harbaugh and John A. Forakis                             --
  19. --                                                                      --
  20. --------------------------------------------------------------------------
  21. --                                                                      --
  22. -- Authors Disclaimer                                                   --
  23. -- "   The Whetstone measure deals only with the most basic scientific/ --
  24. --  computational aspects of the languages and computers and no general --
  25. --  conclusions should be drawn from this work. Application specific    --
  26. --  benchmarks should be written and run by anyone needing to draw      --
  27. --  conclusions reguarding suitability of languages, compilers and      --
  28. --  hardware. This data is reported to stimulate interest and work in   --
  29. --  run time benchmarking and in no way is meant to influence anyone's  --
  30. --  choice of languages or software in any situation "                  --
  31. --                                                                      --
  32. --------------------------------------------------------------------------
  33.  
  34. with CPU_TIME_CLOCK ;
  35. with TEXT_IO;   use TEXT_IO;
  36. -- Change the following line to use the compiler vendors or manufacturers
  37. -- math library.
  38. with FLOAT_MATH_LIB; use FLOAT_MATH_LIB; -- manufacturers routines ( VAX )
  39.  
  40. procedure A000092 is
  41.  --pragma SUPPRESS(ACCESS_CHECK);
  42.  --pragma SUPPRESS(DISCRIMINANT_CHECK);
  43.  --pragma SUPPRESS(INDEX_CHECK);
  44.  --pragma SUPPRESS(LENGTH_CHECK);
  45.  --pragma SUPPRESS(RANGE_CHECK);
  46.  --pragma SUPPRESS(DIVISION_CHECK);
  47.  --pragma SUPPRESS(OVERFLOW_CHECK);
  48.  --pragma SUPPRESS(STORAGE_CHECK);
  49.  --pragma SUPPRESS(ELABORATION_CHECK);
  50.  
  51.   package INT_IO is new INTEGER_IO(INTEGER);  use INT_IO;
  52.   package REAL_IO is new FLOAT_IO(FLOAT);  use REAL_IO;
  53.  
  54.      procedure WHETSTONE(I, NO_OF_CYCLES : in INTEGER;
  55.                          START_TIME,STOP_TIME: out FLOAT) is
  56.  
  57.      -- Calling procedure provides the loop count weight factor, I, and
  58.      -- the encompassing loop count, NO_OF_CYCLES.
  59.  
  60.         type VECTOR is array (INTEGER range <>) of FLOAT;
  61.         X1,X2,X3,X4,X,Y,Z,T,T1,T2 : FLOAT;
  62.         E1 : VECTOR(1..4);
  63.         J,K,L,N1,N2,N3,N4,N5,N6,N7,N8,N9,N10,N11 : INTEGER;
  64.  
  65.         procedure PA(E: in out VECTOR) is
  66.         -- tests computations with an array as a parameter
  67.            J : INTEGER;
  68.            -- T,T2 : FLOAT are global variables
  69.            begin
  70.              J:=0;
  71.              <<LAB>>
  72.              E(1) := (E(1) + E(2) + E(3) - E(4)) * T;
  73.              E(2) := (E(1) + E(2) - E(3) + E(4)) * T;
  74.              E(3) := (E(1) - E(2) + E(3) + E(4)) * T;
  75.              E(4) := (-E(1) + E(2) + E(3) + E(4)) / T2;
  76.              J := J + 1;
  77.              if J < 6 then
  78.                 goto LAB;
  79.              end if;
  80.         end PA;
  81.  
  82.  
  83.         procedure P0 is
  84.         -- tests computations with no parameters
  85.         -- T1,T2 : FLOAT are global
  86.         -- E1 : VECTOR(1..4) is global
  87.         -- J,K,L : INTEGER are global
  88.            begin
  89.              E1(J) := E1(K);
  90.              E1(K) := E1(L);
  91.              E1(L) := E1(J);
  92.            end P0;
  93.  
  94.  
  95.         procedure P3(X,Y: in out FLOAT;  Z : out FLOAT) is
  96.         -- tests computations with simple identifiers as parameters
  97.         -- T,T2 : FLOAT are global
  98.            begin
  99.              X := T * (X + Y);
  100.              Y := T * (X + Y);
  101.              Z := (X + Y) / T2;
  102.            end P3;
  103.  
  104.  
  105.         begin
  106.           -- Set constants
  107.           T := 0.499975;
  108.           T1 := 0.50025;
  109.           T2 := 2.0;
  110.           -- Compute the execution frequency for the benchmark modules
  111.           N1 := 0;      --Module 1 not executed
  112.           N2 := 12 * I;
  113.           N3 := 14 * I;
  114.           N4 := 345*I;
  115.           N5 := 0;      -- Module 5 not executed
  116.           N6 := 210*I;
  117.           N7 := 32*I;
  118.           N8 := 899*I;
  119.           N9 := 616*I;
  120.           N10:= 0;      -- Module 10 not executed
  121.           N11:= 93*I;
  122.  
  123.           START_TIME := FLOAT(CPU_TIME_CLOCK);  --Get Whetstone start time
  124.  
  125.           CYCLE_LOOP:
  126.           for CYCLE_NO in 1..NO_OF_CYCLES loop
  127.              -- Module 1 : computations with simple identifiers
  128.                 X1 := 1.0;
  129.                 X2 := -1.0;
  130.                 X3 := -1.0;
  131.                 X4 := -1.0;
  132.                 for I in 1..N1 loop
  133.                    X1 := (X1 + X2 + X3 - X4) * T;
  134.                    X2 := (X1 + X2 - X3 + X4) * T;
  135.                    X3 := (X1 + X2 + X3 + X4) * T;
  136.                    X4 := (-X1 + X2 + X3 + X4) * T;
  137.                 end loop;
  138.              -- end Module 1
  139.  
  140.              -- Module 2: computations with array elements
  141.                 E1(1) := 1.0;
  142.                 E1(2) := -1.0;
  143.                 E1(3) := -1.0;
  144.                 E1(4) := -1.0;
  145.                 for I in 1..N2 loop
  146.                    E1(1) := (E1(1) + E1(2) + E1(3) - E1(4)) * T;
  147.                    E1(2) := (E1(1) + E1(2) - E1(3) + E1(4)) * T;
  148.                    E1(3) := (E1(1) - E1(2) + E1(3) + E1(4)) * T;
  149.                    E1(4) := (-E1(1) + E1(2) + E1(3) + E1(4)) * T;
  150.                 end loop;
  151.              -- end Module 2
  152.  
  153.              -- Module 3 : passing an array as a parmeter
  154.                 for I in 1..N3 loop
  155.                      PA(E1);
  156.                 end loop;
  157.              -- end Module 3
  158.  
  159.              -- Module 4 : performing conditional jumps
  160.                 J := 1;
  161.                 for I in 1..N4 loop
  162.                    if J=1 then
  163.                        J := 2;
  164.                    else
  165.                        J := 3;
  166.                    end if;
  167.                    if J>2 then
  168.                        J := 0;
  169.                    else
  170.                        J := 1;
  171.                    end if;
  172.                    if J<1 then
  173.                        J := 1;
  174.                    else
  175.                        J := 0;
  176.                    end if;
  177.                 end loop;
  178.              --end Module 4
  179.  
  180.              -- Module 5 : omitted
  181.  
  182.              -- Module 6 : performing integer arithmetic
  183.                 J := 1;
  184.                 K := 2;
  185.                 L := 3;
  186.                 for I in 1..N6 loop
  187.                    J := J * (K-J) * (L-K);
  188.                    K := L*K - (L-J) * K;
  189.                    L := (L-K) * (K+J);
  190.                    E1(L-1) := FLOAT(J+K+L);
  191.                    E1(K-1) := FLOAT(J*K*L);
  192.                 end loop;
  193.              -- end Module 6
  194.  
  195.              -- Module 7 : performing computations using trigonometric
  196.              --            functions
  197.                 X := 0.5;
  198.                 Y := 0.5;
  199.                 for I in 1..N7 loop
  200.                   X := T*ATAN(T2*SIN(X)*COS(X)/(COS(X+Y)+COS(X-Y)-1.0));
  201.                   Y := T*ATAN(T2*SIN(Y)*COS(Y)/(COS(X+Y)+COS(X-Y)-1.0));
  202.                 end loop;
  203.              -- end Module 7
  204.  
  205.              -- Module 8 : procedure calls with simple identifiers as
  206.              --            parameters
  207.                 X := 1.0;
  208.                 Y := 1.0;
  209.                 Z := 1.0;
  210.                 for I in 1..N8 loop
  211.                    P3(X,Y,Z);
  212.                 end loop;
  213.              -- end Module 8
  214.  
  215.              -- Module 9 : array reference and procedure calls with no
  216.              --            parameters
  217.                 J := 1;
  218.                 K := 2;
  219.                 L := 3;
  220.                 E1(1) := 1.0;
  221.                 E1(2) := 2.0;
  222.                 E1(3) := 3.0;
  223.                 for I in 1..N9 loop
  224.                    P0;
  225.                 end loop;
  226.              -- end Module 9
  227.  
  228.              -- Module 10 : integer arithmetic
  229.                 J := 2;
  230.                 K := 3;
  231.                 for I in 1..N10 loop
  232.                    J := J + K;
  233.                    K := K + J;
  234.                    J := K - J;
  235.                    K := K - J - J;
  236.                 end loop;
  237.              -- end Module 10
  238.  
  239.              -- Module 11 : performing computations using standard
  240.              --            mathematical functions
  241.                 X := 0.75;
  242.                 for I in 1..N11 loop
  243.                    X := SQRT(EXP(LOG(X)/T1));
  244.                 end loop;
  245.              -- end Moudle 11
  246.  
  247.           end loop CYCLE_LOOP;
  248.  
  249.           STOP_TIME := FLOAT(CPU_TIME_CLOCK);    --Get Whetstone stop time
  250.     end WHETSTONE;
  251.  
  252.     procedure COMPUTE_WHETSTONE_KIPS is
  253.        -- Variables used to control execution of benchmark and to
  254.        -- compute the Whetstone rating :
  255.  
  256.           NO_OF_RUNS : INTEGER;   -- Number of times the benchmark is executed
  257.           NO_OF_CYCLES : INTEGER; -- Number of times the group of benchmark
  258.                                   -- modules is executed
  259.           I : INTEGER;
  260.              -- Factor weighting number of times each module loops
  261.              -- A value of ten gives a total weight for modules of
  262.              -- approximately one million Whetstone instructions
  263.           START_TIME : FLOAT;
  264.                      -- Time at which execution of benchmark modules begins
  265.           STOP_TIME : FLOAT;
  266.                     -- Time at which execution of benchmark modules ends
  267.                     -- (time for NO_OF_CYCLES)
  268.           ELAPSED_TIME : FLOAT;
  269.                        -- Time between START_TIME and STOP_TIME
  270.           MEAN_TIME : FLOAT;     -- Average time per cycle
  271.           RATING : FLOAT;    -- Thousands of Whetstone instructions per sec
  272.           MEAN_RATING : FLOAT;     -- Average Whetstone rating
  273.           INT_RATING : INTEGER;    -- Integer value of KWIPS
  274.  
  275.           begin
  276.             NEW_LINE; PUT_LINE("ADA Whetstone benchmark"); NEW_LINE;
  277.             PUT_LINE("A000092 using manufacturers math routines");
  278.             NEW_LINE;
  279.  
  280.             MEAN_TIME := 0.0;
  281.             MEAN_RATING := 0.0;
  282.             NO_OF_CYCLES := 10;
  283.             NO_OF_RUNS := 5;
  284.             I := 10;
  285.  
  286.             RUN_LOOP:
  287.             for RUN_NO in 1..NO_OF_RUNS loop
  288.                -- Call the Whetstone benchmark parocedure
  289.                WHETSTONE(I,NO_OF_CYCLES,START_TIME,STOP_TIME);
  290.  
  291.                -- Write the Whetstone start time
  292.                NEW_LINE; PUT("Whetstone start time: "); PUT(START_TIME,5,2,0);
  293.                PUT_LINE(" seconds");
  294.  
  295.                -- Write the Whetstone stop time
  296.                NEW_LINE;   PUT("Whetstone stop time : ");
  297.                PUT(STOP_TIME,5,2,0);     PUT_LINE(" seconds ");
  298.  
  299.                -- Compute and write elapsed time
  300.                ELAPSED_TIME := STOP_TIME - START_TIME;
  301.  
  302.                NEW_LINE;  PUT("Elapsed time for "); PUT(NO_OF_CYCLES,3);
  303.                PUT(" cycles : ");  PUT(ELAPSED_TIME,5,2,0);
  304.                PUT_LINE(" seconds");
  305.  
  306.                -- Sum time in milliseconds per cycle
  307.                MEAN_TIME := MEAN_TIME + (ELAPSED_TIME*1000.0)/FLOAT(NO_OF_CYCLES);
  308.  
  309.                -- Calculate the Whetstone rating based on the time for
  310.                -- the number of cycles just executed and write
  311.                RATING := (1000.0 * FLOAT(NO_OF_CYCLES))/ELAPSED_TIME;
  312.  
  313.                -- Sum Whetstone rating
  314.                MEAN_RATING := MEAN_RATING + RATING;
  315.                INT_RATING := INTEGER(RATING);
  316.  
  317.                NEW_LINE;  PUT("Whetstone rating : ");  PUT(INT_RATING);
  318.                PUT_LINE(" KWIPS");  NEW_LINE;
  319.  
  320.                -- Reset NO_OF_CYCLES for next run using ten cycles more
  321.                NO_OF_CYCLES := NO_OF_CYCLES + 10;
  322.             end loop RUN_LOOP;
  323.  
  324.             -- Compute average time in millieseconds per cycle and write
  325.             MEAN_TIME := MEAN_TIME/FLOAT(NO_OF_RUNS);
  326.  
  327.             NEW_LINE;  PUT("Average time per cycle : ");
  328.             PUT(MEAN_TIME,5,2,0);   PUT_LINE(" milliseconds");
  329.  
  330.             -- Calculate average Whetstone rating and write
  331.             MEAN_RATING := MEAN_RATING/FLOAT(NO_OF_RUNS);
  332.             INT_RATING := INTEGER(MEAN_RATING);
  333.  
  334.             NEW_LINE;  PUT(" Average Whetstone rating : ");
  335.             PUT(INT_RATING);  PUT_LINE(" KWIPS");
  336.             NEW_LINE; NEW_LINE;
  337.  
  338.          end COMPUTE_WHETSTONE_KIPS;
  339.  
  340.          begin
  341.             COMPUTE_WHETSTONE_KIPS;
  342.          end A000092;
  343.