with Instrument;
use Instrument;
-- BENCHMARK   CHARACTER STRING SEARCH.

procedure Chssa3 is
    pragma Suppress (Access_Check);
    pragma Suppress (Discriminant_Check);
    pragma Suppress (Index_Check);
    pragma Suppress (Length_Check);
    pragma Suppress (Range_Check);
    pragma Suppress (Division_Check);
    pragma Suppress (Overflow_Check);
    pragma Suppress (Storage_Check);

    subtype Short_Integer is Integer;

    type String is array (1 .. 120) of Character;
    Numiterations : constant Integer := 10000;
    -- TO MAKE IT MILLISECONDS/SEC
    Position_To_Pass : Short_Integer;

    function Strsch (S, K : in String; Ns, Nk : in Short_Integer)
                    return Short_Integer is

        I, J : Short_Integer;
        Base, Ksave, Cont : Short_Integer;
        Kend, Ssave : Short_Integer;
        R : Short_Integer;
    begin
        Base := 1;
        Ksave := 1;
        Cont := Ns - Nk + Base;
        Kend := Ksave + Nk - 1;
        I := 1;
        J := 1;
        <<Top>>
            while S (I) /= K (J) loop
                if I >= Cont then
                    R := -1;
                    goto Finish;
                end if;
                I := I + 1;
            end loop;
        Ssave := I;
        J := J + 1;
        while J <= Kend loop
            I := I + 1;
            if S (I) /= K (J) then
                I := Ssave + 1;
                J := Ksave;
                goto Top;

            end if;
            J := J + 1;
        end loop;
        R := Ssave - Base + 1;
        <<Finish>> return (R);
    end Strsch;

    procedure Benche is
        S, K : String;
        Position : Short_Integer := 0;
        Ns, Nk : Short_Integer;
    begin
        S :=
           "000000000000000000000000000000000000000000000000000000000000HERE" &
              "000000" & "00000000000000000000HERE IS A MATCH000000000000000";
        K :=
           "HERE IS A MATCH                                                 " &
              "      " & "                                                  ";
        Ns := 120;
        Nk := 15;
        Position := Strsch (S, K, Ns, Nk);
        Position_To_Pass := Position;
    end Benche;


begin
    Start ("CHSSA3", "Char. String Search (pragma suppress)");
    for I in 1 .. Numiterations loop
        Benche;
    end loop;
    Stop;
end Chssa3;