comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Timing code blocks
Date: Fri, 5 Mar 2010 09:49:42 +0100
Date: 2010-03-05T09:49:40+01:00	[thread overview]
Message-ID: <7ihvqmo8zt91.eraboux3xzzj$.dlg@40tude.net> (raw)
In-Reply-To: 12e4d91f-9c23-49fb-a413-97c0375a1668@s36g2000prf.googlegroups.com

On Fri, 5 Mar 2010 00:16:52 -0800 (PST), deadlyhead wrote:

> On Mar 4, 11:55�pm, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
>>
>> This is an ancient bug, which managed to survive a number of GNAT compiler
>> versions.
>>
>> As a workaround, add delay 0.0 at the beginning of your program:
>>
>>> ----------------------------------------------------------------------
>>
>>> -- �A test of the cost of conditionals
>>
>>> with Ada.Text_IO; �use Ada.Text_IO;
>>> with Ada.Real_Time; use Ada.Real_Time;
>>> procedure Conditional_Test is
>>
> 
> Exactly what was needed.  Thank 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 tasking
stuff somehow wakes the RTL up. That is probably the reason, I suggest, why
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.  With -O0, the second loop is faster by an
> average of 10%.  I would have thought the extra conditional would have
> 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 := Clock;
for I in 1..N loop
   ... -- measured stuff
end loop;
D1 := Clock - T;

T := Clock;
for I in 1..N loop
   ... -- measured stuff
   ... -- measured stuff (do it twice)
end loop;
D2 := 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. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2010-03-05  8:49 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-05  6:34 Timing code blocks deadlyhead
2010-03-05  7:55 ` Dmitry A. Kazakov
2010-03-05  8:16   ` deadlyhead
2010-03-05  8:49     ` Dmitry A. Kazakov [this message]
2010-03-05 12:41       ` Alex Mentis
2010-03-05 21:15         ` Jeffrey R. Carter
2010-03-05 23:35         ` Simon Wright
2010-03-06  9:50           ` Georg Bauhaus
2010-03-06 12:06             ` Simon Wright
2010-03-07  1:02               ` Georg Bauhaus
2010-03-08 12:16                 ` Alex Mentis
2010-03-06 12:12           ` Alex Mentis
2010-03-05  8:33   ` Ludovic Brenta
2010-03-05  9:04     ` Dmitry A. Kazakov
2010-03-05 15:27       ` Reporting bugs (was: Timing code blocks) Ludovic Brenta
2010-03-06  7:13         ` Stephen Leake
2010-03-05 23:35   ` Timing code blocks Simon Wright
2010-03-05  8:21 ` Niklas Holsti
2010-03-05 20:17   ` Simon Wright
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox