
-- PERFORMANCE MEASUREMENT : Measure simple "for" loop time
--                           loop is run 100 times
--                           time reported is for once through

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

procedure L000001 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
    Case_Count : constant := 100;

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; -- something to do
                Remote;                   -- that can not be pulled out of loop
                Global := Global + A_One; -- repeated here 100 times
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
                Global := Global + A_One;
                Remote;
            end loop;
        end loop;
        Global := Global / Case_Count;
        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
                for I in 1 .. 100 loop
                    Global := Global + A_One; -- same computation as above
                    Remote;                   -- now in loop
                end loop;
            end loop;
        end loop;
        Global := Global / Case_Count;
        Iteration.Stop_Test (Global, Check_Times);
        Iteration.Test_Stable (Iteration_Count, Stable);
        exit when Stable;
    end loop;
--
    Iteration.Feature_Times (Cpu_Time, Wall_Time);
    Cpu_Time := Duration (Cpu_Time / Case_Count);
    Wall_Time := Duration (Wall_Time / Case_Count);

--
-- Printout
--
    Piwg_Io.Piwg_Output ("L000001", "Iteration", Cpu_Time,
                         Wall_Time, Iteration_Count,
                         "Simple ""for"" loop time ", "for I in 1 .. 100 loop ",
                         "time reported is for once through loop ");

end L000001;