with Instrument;
use Instrument;

-- This test evaluates the code efficiency of a binary case statement,
-- i.e., one in which the case alternative is selected through a single
-- choice value.

-- The purpose of this test is to offer the compiler a case statement
-- that may be implemented by an explicit comparison to the choice
-- value.

-- The global variable is used in the case expression to select the choice
-- alternative in the case statement.  In the test version the alternative
-- is explicitly specified by a single choice value and comprise a
-- camouflaged assignment of this value 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 Csbta1 is

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

begin

    Start ("CSBTA1", "Case Statement Binary Test (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 others =>
            Let (Global, Ident (2));
        end if;                                -- included in control version
        --  end case;

    end loop;
    Stop;

end Csbta1;