From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,101c38a932801b81 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!a70g2000hsh.googlegroups.com!not-for-mail From: george.priv@gmail.com Newsgroups: comp.lang.ada Subject: Re: Ada.Real_Time behavior with GNAT Date: Sat, 29 Mar 2008 09:50:56 -0700 (PDT) Organization: http://groups.google.com Message-ID: <4982c29a-098c-4ff4-ac59-59d54ac65340@a70g2000hsh.googlegroups.com> References: NNTP-Posting-Host: 151.196.71.114 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1206809456 21179 127.0.0.1 (29 Mar 2008 16:50:56 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 29 Mar 2008 16:50:56 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: a70g2000hsh.googlegroups.com; posting-host=151.196.71.114; posting-account=VnNb3AoAAACTpRtCcTrcjmPX7cs92k1Q User-Agent: G2/1.0 X-HTTP-Via: 1.1 SPARKS X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:20629 Date: 2008-03-29T09:50:56-07:00 List-Id: On Mar 29, 9:51 am, kongra wrote: > 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. Your program should overflow (unless you suppress checks) raising Constraint_Error for Val. It runs fine on Vista though after fixing overflow problem George.