ada-examples-4-10-branchada-examples-4-9-branch
Last change
on this file since f27b251 was
f27b251,
checked in by Joel Sherrill <joel.sherrill@…>, on 09/27/07 at 14:42:22
|
2007-09-27 Joel Sherrill <joel.sherrill@…>
- .cvsiginore, ChangeLog?, Makefile, README, delay_until.adb: New files.
|
-
Property mode set to
100644
|
File size:
1.7 KB
|
Line | |
---|
1 | with Ada.Real_Time; |
---|
2 | with Ada.Text_Io; |
---|
3 | |
---|
4 | use type Ada.Real_Time.Time; |
---|
5 | use type Ada.Real_Time.Time_Span; |
---|
6 | |
---|
7 | |
---|
8 | procedure Delay_Until_Test is |
---|
9 | Next_Wakeup : Ada.Real_Time.Time; |
---|
10 | Period : constant Ada.Real_Time.Time_Span := Ada.Real_Time.Nanoseconds (16666667); |
---|
11 | -- Period : constant Ada.Real_Time.Time_Span := Ada.Real_Time.Nanoseconds (20000); |
---|
12 | |
---|
13 | Iterations : constant := 1000; |
---|
14 | Actual_Span : array (1..Iterations) of Ada.Real_Time.Time_Span; |
---|
15 | Average_Span : Ada.Real_Time.Time_Span := Ada.Real_Time.Time_Span_Zero; |
---|
16 | Max_Span : Ada.Real_Time.Time_Span := Ada.Real_Time.Time_Span_First; |
---|
17 | Min_Span : Ada.Real_Time.Time_Span := Ada.Real_Time.Time_Span_Last; |
---|
18 | |
---|
19 | begin |
---|
20 | Ada.Text_Io.Put_Line (Integer'Image (Iterations) & " iterations with " & |
---|
21 | Duration'Image (Ada.Real_Time.To_Duration(Period)) & "s period"); |
---|
22 | Next_Wakeup := Ada.Real_Time.Clock + Period; |
---|
23 | for Count in 1..Iterations loop |
---|
24 | delay until Next_Wakeup; |
---|
25 | |
---|
26 | Actual_Span (Count) := Ada.Real_Time.Clock - (Next_Wakeup - Period); |
---|
27 | Average_Span := Average_Span + (Actual_Span (Count) / Iterations); |
---|
28 | if Actual_Span (Count) > Max_Span then |
---|
29 | Max_Span := Actual_Span (Count); |
---|
30 | end if; |
---|
31 | if Actual_Span (Count) < Min_Span then |
---|
32 | Min_Span := Actual_Span (Count); |
---|
33 | end if; |
---|
34 | |
---|
35 | Next_Wakeup := Next_Wakeup + Period; |
---|
36 | end loop; |
---|
37 | |
---|
38 | Ada.Text_Io.Put_Line ("Average delay is" & Duration'Image (Ada.Real_Time.To_Duration (Average_Span)) & "s"); |
---|
39 | Ada.Text_Io.Put_Line ("Maximum delay is" & Duration'Image (Ada.Real_Time.To_Duration (Max_Span)) & "s"); |
---|
40 | Ada.Text_Io.Put_Line ("Minimum delay is" & Duration'Image (Ada.Real_Time.To_Duration (Min_Span)) & "s"); |
---|
41 | end Delay_Until_Test; |
---|
Note: See
TracBrowser
for help on using the repository browser.