with Instrument;
use Instrument;

----------------
-- Sparse Case 1..50
----------------

-- These five tests evaluate the code efficiency of a sparse case
-- statement, i.e., one in which the case alternatives are selected
-- by two choice values from an extensive range of case expression values,
-- in which the difference between the values is varied for each test.

-- The purpose of these tests is to offer the compiler different case
-- statements that may be implemented by explicit comparison with the
-- choice values or with a jump table when the difference between the
-- two choice values is small.

-- The global variable is used in the case expression to select one
-- of the three alternatives that are included in the case statement.
-- In the test version, each alternative is explicitly specified by
-- a range of consecutive values and comprises a camouflaged assignment
-- of the first value in the choice range to the global variable.
-- The value of the case expression will always cause execution of the
-- first case alternative; however, this condition is carefully protected
-- from detection by the compiler so that no optimization of the case
-- statement is performed.  In the noise version, the case statement
-- is removed to leave an if-then-else construct comprising an
-- equivalent number of assignments so that the code efficiency can be
-- derived.

procedure Csstc1 is

    package New_Procs is new Procs (Integer);
    use New_Procs;

begin

    Start ("CSSTC1", "Case Statement Sparse Test w/range 1..50 (control)");
    for I in 1 .. 10000 loop

        Let (Global, Ident (1));
        --  case Global is
        --    when 1 =>
        if Global = Ident (1) then
            -- always true
            Let (Global, Ident (1));
        else
            Let (Global, Ident (0));
            --      end if;                                -- included in test version
            --    when 50 =>
            Let (Global, Ident (50));
            --    when others =>
            null;
        end if;                                -- included in control version
        --    end case;

    end loop;
    Stop;

end Csstc1;