summaryrefslogblamecommitdiffstats
path: root/delay_until/delay_until.adb
blob: 193cd4b27847be9ca112cef5da058ccda16c041d (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11



        






                                 
                        
                                    


                                                           







                                                                           





                                                               















                                                                          
















                                                                      
--
--  $Id$
--

with Ada.Real_Time;
with Ada.Text_Io;

use type Ada.Real_Time.Time;
use type Ada.Real_Time.Time_Span;


procedure Delay_Until is
   Next_Wakeup : Ada.Real_Time.Time;
   Period      : constant Ada.Real_Time.Time_Span :=
                    Ada.Real_Time.Nanoseconds (16666667);
                    --   Ada.Real_Time.Nanoseconds (20000);

   Iterations : constant := 1000;
   Actual_Span : array (1..Iterations) of Ada.Real_Time.Time_Span;
   Average_Span : Ada.Real_Time.Time_Span := Ada.Real_Time.Time_Span_Zero;
   Max_Span     : Ada.Real_Time.Time_Span := Ada.Real_Time.Time_Span_First;
   Min_Span     : Ada.Real_Time.Time_Span := Ada.Real_Time.Time_Span_Last;

begin
   Ada.Text_Io.Put_Line ("*** Delay Until Variation Test ***");
   Ada.Text_Io.Put_Line (
      Integer'Image (Iterations) & " iterations with " &
      Duration'Image (Ada.Real_Time.To_Duration(Period)) &
      "s period"
   );
   Next_Wakeup := Ada.Real_Time.Clock + Period;
   for Count in 1..Iterations loop
      delay until Next_Wakeup;

      Actual_Span (Count) := Ada.Real_Time.Clock - (Next_Wakeup - Period);
      Average_Span := Average_Span + (Actual_Span (Count) / Iterations);
      if Actual_Span (Count) > Max_Span then
         Max_Span := Actual_Span (Count);
      end if;
      if Actual_Span (Count) < Min_Span then
         Min_Span := Actual_Span (Count);
      end if;

      Next_Wakeup := Next_Wakeup + Period;
   end loop;

   Ada.Text_Io.Put_Line (
      "Average delay is" &
      Duration'Image (Ada.Real_Time.To_Duration (Average_Span)) &
      "s"
   );
   Ada.Text_Io.Put_Line (
      "Maximum delay is" &
      Duration'Image (Ada.Real_Time.To_Duration (Max_Span)) &
      "s"
   );
   Ada.Text_Io.Put_Line (
      "Minimum delay is" &
       Duration'Image (Ada.Real_Time.To_Duration (Min_Span)) &
       "s"
   );
   Ada.Text_Io.Put_Line ("*** END OF Delay Until Variation Test ***");
end Delay_Until;