Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Ada > Ada.Real_Time b...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 15 Topic 5622 of 5697
Post > Topic >>

Ada.Real_Time behavior with GNAT

by kongra <kongra@[EMAIL PROTECTED] > Mar 29, 2008 at 06:51 AM

Hi everybody.

I have a question related to the Ada.Real_Time package. When I compile
the following code using GNAT GPL 2007 on Windows XP SP2 I observe
some strange looking behavior.

with Ada.Real_Time;
with Ada.Text_IO;

procedure Timing is
   Start_T : Ada.Real_Time.Time;
   End_T   : Ada.Real_Time.Time;
   Total_T : Duration;
   Sleep_T : constant Duration := Duration (0.0001);

   use Ada.Real_Time;

   Val : Integer := 0;
begin
   -- delay Sleep_T;
   Start_T := Ada.Real_Time.Clock;
   for K in 1 .. 10 loop
      for I in 1 .. 10_000_000 loop
         Val := Val + I;
      end loop;
   end loop;
   End_T   := Ada.Real_Time.Clock;
   Total_T := Ada.Real_Time.To_Duration (End_T - Start_T);
   Ada.Text_IO.Put_Line (Integer'Image (Val));
   Ada.Text_IO.Put_Line (Duration'Image (Total_T));
end Timing;

The compilation command is pretty straightforward: gnatmake Timing.adb
-o timing.exe. Running timing.exe I get

1432236160
0.000000000

To my surprise the total time is 0 here, though performing all the
computations takes some observable time. However removing comment in
the line containing statement delay Sleep_T; causes

1432236160
0.431441426

Apparently the total duration seems correct now. I get a similar
change by putting

with Ada.Calendar;

to the compilation unit (without completely using it). Moreover the
delay statement has got the same impact on the program execution even
when it's placed in some procedure other than Timing and the procedure
is not used at all.

I tried the same code in a bigger project using switches like those in
the Ada Wikibooks examples, getting the same.

Can it be explained or is there something I don't know about timing in
Ada ? I'm a beginner in Ada (after 7+ years Java coding) and I think
it's a great programming language, worth to be promoted among
students. But this one really surprised me even if I was able to avoid
using Ada.Calendar (for example prohibited by Ravenscar profile) using
a hack with delay.

Best regards,

Konrad Grzanek.




 15 Posts in Topic:
Ada.Real_Time behavior with GNAT
kongra <kongra@[EMAIL   2008-03-29 06:51:58 
Re: Ada.Real_Time behavior with GNAT
george.priv@[EMAIL PROTEC  2008-03-29 09:50:56 
Re: Ada.Real_Time behavior with GNAT
Georg Bauhaus <rm.tsoh  2008-03-29 18:29:48 
Re: Ada.Real_Time behavior with GNAT
Simon Wright <simon.j.  2008-03-29 18:11:29 
Re: Ada.Real_Time behavior with GNAT
"Dmitry A. Kazakov&q  2008-03-29 19:25:05 
Re: Ada.Real_Time behavior with GNAT
george.priv@[EMAIL PROTEC  2008-03-29 12:06:38 
Re: Ada.Real_Time behavior with GNAT
Konrad Grzanek <kongra  2008-03-29 12:15:41 
Re: Ada.Real_Time behavior with GNAT
Konrad Grzanek <kongra  2008-03-29 12:46:16 
Re: Ada.Real_Time behavior with GNAT
Georg Bauhaus <rm.tsoh  2008-03-30 01:14:29 
Re: Ada.Real_Time behavior with GNAT
george.priv@[EMAIL PROTEC  2008-03-29 14:21:45 
Re: Ada.Real_Time behavior with GNAT
Konrad Grzanek <kongra  2008-03-29 14:49:16 
Semantics of statement reordering relevant to Ada.Real_Time
Eric Hughes <eric.eh9@  2008-03-30 10:12:25 
Re: Semantics of statement reordering relevant to Ada.Real_Time
Robert A Duff <bobduff  2008-03-30 14:59:21 
Re: Semantics of statement reordering relevant to Ada.Real_Time
Eric Hughes <eric.eh9@  2008-03-30 14:12:20 
Re: Semantics of statement reordering relevant to Ada.Real_Time
Robert A Duff <bobduff  2008-03-30 17:28:19 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed May 14 3:31:06 CDT 2008.