with Proc_Package_13;
use Proc_Package_13;
with Remote_Global;
use Remote_Global; -- control optimization
with Iteration; -- obtain stable measurement
with Piwg_Io; -- output results

procedure P000013 is  -- main procedure to execute
    Cpu_Time : Duration; -- CPU time for one feature execution
    Wall_Time : Duration; -- WALL time for one feature execution
    Check_Times : constant := 100; -- inside loop count and check
    Iteration_Count : Integer; -- set and varied by ITERATION package
    Stable : Boolean; -- true when measurement stable
    A : My_Record := (A_One, A_One + A_One, A_One + A_One + A_One);

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.R1 + A.R2 + A.R3 - A.R1 - A.R2 -
                             A.R3 + A.R1 + A.R2 - A.R3 + A.R1 + A.R1 +
                             A.R2 - A.R3 + A.R1 + A.R2 - A.R3 +
                             A.R1 + A.R2 - A.R3 - A.R1 + 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 (A, A, A, A, A, A, A, A, A, A,
                        A, A, A, A, A, A, A, A, A, A);
                -- this has control global increment and call inside
            end loop;
        end loop;
        Iteration.Stop_Test (Global, Check_Times);
        Iteration.Test_Stable (Iteration_Count, Stable);
        exit when Stable;
    end loop;
--
    Iteration.Feature_Times (Cpu_Time, Wall_Time);

--
-- Printout
--
    Piwg_Io.Piwg_Output ("P000013", "Procedure", Cpu_Time,
                         Wall_Time, Iteration_Count,
                         " Procedure call and return time measurement",
                         " twenty composite 'in' parameters ",
                         " the composite type is a three component record");

end P000013;