-- PERFORMANCE MEASUREMENT : Minimum procedure call and return time
--                           procedure local
--                           no parameters

with Remote_Global;
use Remote_Global;
with Iteration;
with Piwg_Io;

procedure P000001 is  -- main procedure to execute

    Cpu_Time : Duration;
    Wall_Time : Duration;
    Check_Times : constant := 100;
    Iteration_Count : Integer;
    Its_Ok : Boolean;

--

    procedure Proc_0 is  -- may be inlined thus zero time
    begin
        Global := Global + A_One;
        Remote;
    end Proc_0;

begin

    Iteration.Start_Control;  -- dummy to bring in pages on some machines

    delay 0.5;  -- wait for stable enviornment on some machines

    Iteration.Initialize (Iteration_Count);

    loop  -- until stable measurement, ITERATION_COUNT increases each time

--
-- Control loop
--
        Iteration.Start_Control;
        for J in 1 .. Iteration_Count loop
            Global := 0;
            for Inside_Loop in 1 .. Check_Times loop
                Global := Global + A_One;
                Remote;
            end loop;
        end loop;
        Iteration.Stop_Control (Global, Check_Times);

--
-- Test loop
--
        Iteration.Start_Test;
        for J in 1 .. Iteration_Count loop
            Global := 0;
            for Inside_Loop in 1 .. Check_Times loop
                Proc_0;  -- this has control global increment and call inside
            end loop;
        end loop;
        Iteration.Stop_Test (Global, Check_Times);
        Iteration.Test_Stable (Iteration_Count, Its_Ok);
        exit when Its_Ok;
    end loop;
--
    Iteration.Feature_Times (Cpu_Time, Wall_Time);

--
-- Printout
--
    Piwg_Io.Piwg_Output
       ("P000001", "Procedure", Cpu_Time, Wall_Time, Iteration_Count,
        " Procedure call and return time ( may be zero if automatic inlining ) ",
        " procedure is local ", " no parameters ");

end P000001;