TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Forum View

Use Monospaced Font
Show Text Part by Default
Condense Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Content-Transfer-Encoding:
7bit
Sender:
"Team Ada: Ada Advocacy Issues (83 & 95)" <[log in to unmask]>
Subject:
From:
Jeff Carter <[log in to unmask]>
Date:
Sat, 4 Nov 2000 22:17:44 -0600
Content-Type:
text/plain; charset=us-ascii
MIME-Version:
1.0
Reply-To:
Jeff Carter <[log in to unmask]>
Parts/Attachments:
text/plain (122 lines)
Without addressing the ways that Windows can be made to provide
microsecond accuracy, which I have seen discussed, perhaps here or on
comp.lang.ada, I must say that I have been unable to get the program you
posted to output numbers within 20% of the numbers you posted. I also
have no idea why you have the 30-second delay at the end of the program,
but it would make the execution time of the program exceed 90 seconds.

I have run the following modification of your program:

with Ada.Real_Time; use Ada.Real_Time;
with Ada.Text_Io;

procedure Test_Time is
   -- ----------------------------------------------------------
   --  GET THE STARTING TIME, LOOP, GET THE END TIME, SUBSTRACT
   -- ----------------------------------------------------------

   Time_Start      : Ada.Real_Time.Time;
   Time_End        : Ada.Real_Time.Time;
   Time_Difference : Ada.Real_Time.Time_Span;
   Time_Duration   : Duration;
begin -- Test_Time
   for J in 1 .. 10 loop
      Time_Start := Ada.Real_Time.Clock;

      for I in 1 .. 1 loop
         delay 60.00;
      end loop;

      Time_End := Ada.Real_Time.Clock;
      Time_Difference := Time_End - Time_Start;
      Time_Duration := Ada.Real_Time.To_Duration (Time_Difference);

      Ada.Text_Io.Put ("Time Difference: ");
      Ada.Text_Io.Put_Line (Duration'Image (Time_Duration) );
   end loop;
end Test_Time;

on a Win98 machine and obtained the following output:

Time Difference:  60.002681071
Time Difference:  60.000495315
Time Difference:  60.000772725
Time Difference:  60.000887544
Time Difference:  60.000876649
Time Difference:  60.000895087
Time Difference:  60.000931963
Time Difference:  60.000733335
Time Difference:  60.000900115
Time Difference:  60.000691430

Thus we see that the overhead is typically less than 1 millisecond.

Processor: AMD K6-2 3D-NOW 400 Mhz
OS:        Windows 98
Compiler:  GNAT 3.13p
Options:   -gnatwu -gnato -O2 -gnatn

As expected, the program takes about 10 minutes to run.

In any case, you should be using the delay until statement to obtain
accurately repeated intervals.

Altering the program to

with Ada.Real_Time; use Ada.Real_Time;
with Ada.Text_Io;

procedure Test_Time is
   -- ----------------------------------------------------------
   --  GET THE STARTING TIME, LOOP, GET THE END TIME, SUBSTRACT
   -- ----------------------------------------------------------

   Time_Start      : Ada.Real_Time.Time;
   Time_End        : Ada.Real_Time.Time;
   Time_Difference : Ada.Real_Time.Time_Span;
   Time_Duration   : Duration;
   Next            : Time;

   Interval : constant Ada.Real_Time.Time_Span :=
      Ada.Real_Time.To_Time_Span
         (0.00344827586206896551724137931034483);
begin -- Test_Time
   for J in 1 .. 10 loop
      Time_Start := Ada.Real_Time.Clock;
      Next := Time_Start + Interval;

      for I in 1 .. 17_400 loop
         delay until Next;

         Next := Next + Interval;
      end loop;

      Time_End := Ada.Real_Time.Clock;
      Time_Difference := Time_End - Time_Start;
      Time_Duration := Ada.Real_Time.To_Duration (Time_Difference);

      Ada.Text_Io.Put ("Time Difference: ");
      Ada.Text_Io.Put_Line (Duration'Image (Time_Duration) );
   end loop;
end Test_Time;

outputs

Time Difference:  60.002944234
Time Difference:  60.004521531
Time Difference:  59.999996647
Time Difference:  60.000005029
Time Difference:  60.000037714
Time Difference:  60.000008381
Time Difference:  60.000009219
Time Difference:  60.000003353
Time Difference:  60.000001677
Time Difference:  60.004129301

which may be acceptable for your purposes.

--
Jeff Carter
"You tiny-brained wipers of other people's bottoms!"
Monty Python & the Holy Grail

ATOM RSS1 RSS2