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: a07f3367d7,c8acfc87fbb1813d X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!k17g2000yqb.googlegroups.com!not-for-mail From: Alex Mentis Newsgroups: comp.lang.ada Subject: Re: Timing code blocks Date: Fri, 5 Mar 2010 04:41:12 -0800 (PST) Organization: http://groups.google.com Message-ID: <196b2f55-be6e-44f1-85c2-5554a4b4f137@k17g2000yqb.googlegroups.com> References: <2d5bead9-72f9-4c84-9ac1-a058c2591ef1@c37g2000prb.googlegroups.com> <13j6juslcud2k.1n4jnpj74p3k$.dlg@40tude.net> <12e4d91f-9c23-49fb-a413-97c0375a1668@s36g2000prf.googlegroups.com> <7ihvqmo8zt91.eraboux3xzzj$.dlg@40tude.net> NNTP-Posting-Host: 134.240.241.2 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1267792872 25745 127.0.0.1 (5 Mar 2010 12:41:12 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 5 Mar 2010 12:41:12 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: k17g2000yqb.googlegroups.com; posting-host=134.240.241.2; posting-account=CedHywoAAAAcVQwJt5x8TeyAwJA5ElaR User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8 (.NET CLR 3.5.30729),gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:9427 Date: 2010-03-05T04:41:12-08:00 List-Id: On Mar 5, 3:49=A0am, "Dmitry A. Kazakov" wrote: > On Fri, 5 Mar 2010 00:16:52 -0800 (PST), deadlyhead wrote: > > On Mar 4, 11:55=A0pm, "Dmitry A. Kazakov" > > wrote: > > >> This is an ancient bug, which managed to survive a number of GNAT comp= iler > >> versions. > > >> As a workaround, add delay 0.0 at the beginning of your program: > > >>> ---------------------------------------------------------------------= - > > >>> -- =A0A test of the cost of conditionals > > >>> with Ada.Text_IO; =A0use Ada.Text_IO; > >>> with Ada.Real_Time; use Ada.Real_Time; > >>> procedure Conditional_Test is > > > Exactly what was needed. =A0Thank you! > > > Do you happen to know if this bug has been fixed in the current > > development branch? (At home I compile GNAT based on GCC 4.4, but > > haven't done any real-time tests with it yet.) > > AFAIK it is still present in GNAT Pro 6.3.1, which is the latest version = of > GNAT. > > > This seems like an > > unfortunate bug to have lying around in an otherwise respected > > compiler. > > Yes, but in real-life applications it does not show itself, because taski= ng > stuff somehow wakes the RTL up. That is probably the reason, I suggest, w= hy > none of paying customers had yet reported it to AdaCore. > > > BTW, my test results with -O3 and -Os, there is no difference in > > performance between the two loops, and -Os produces code that is about > > 33% faster than -O3. =A0With -O0, the second loop is faster by an > > average of 10%. =A0I would have thought the extra conditional would hav= e > > been costlier. > > Niklas has posted an excellent comment regarding performance measures. It > is quite difficult to do time measurements right in presence of -O2/3. > > As a small addition, here is a technique I am using to subtract looping > overhead: > > T :=3D Clock; > for I in 1..N loop > =A0 =A0... -- measured stuff > end loop; > D1 :=3D Clock - T; > > T :=3D Clock; > for I in 1..N loop > =A0 =A0... -- measured stuff > =A0 =A0... -- measured stuff (do it twice) > end loop; > D2 :=3D Clock - T; > > (D2 - D1) / N is the average time spent on measured stuff without the > overhead caused by looping. Important, as Niklas has pointed out, to fool > the compiler so, that it will not optimize out the things you are > measuring... > > -- > Regards, > Dmitry A. Kazakovhttp://www.dmitry-kazakov.de Confirmed: the bug is still present in GNAT GPL 2009. The same code, timed using Ada.Calendar seems to work just fine, though. Interesting, and good to know about.