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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC 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-7-bit Path: g2news1.google.com!news4.google.com!feeder3.cambriumusenet.nl!feeder1.cambriumusenet.nl!feed.tweaknews.nl!85.158.31.10.MISMATCH!newsfeed-0.progon.net!progon.net!newsfeed.ision.net!newsfeed2.easynews.net!ision!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Timing code blocks Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <2d5bead9-72f9-4c84-9ac1-a058c2591ef1@c37g2000prb.googlegroups.com> Date: Fri, 5 Mar 2010 08:55:19 +0100 Message-ID: <13j6juslcud2k.1n4jnpj74p3k$.dlg@40tude.net> NNTP-Posting-Date: 05 Mar 2010 08:55:17 CET NNTP-Posting-Host: e5d783c9.newsspool2.arcor-online.net X-Trace: DXC==mKZ\?L0]VDI7\_^6>c20JA9EHlD;3YcB4Fo<]lROoRA8kF2l0Vc@ X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:9413 Date: 2010-03-05T08:55:17+01:00 List-Id: On Thu, 4 Mar 2010 22:34:47 -0800 (PST), deadlyhead wrote: > I've been trying to determine if there is any significant performance > difference between two functionally equivalent pieces of code. I've > done the standard thing and, using the Ada.Real_Time package, I'm > saving the time when the code starts, then the time when the code > ends, then examining the difference between them after the code runs. > > The problem I'm having, though, is that the timing just isn't > happening. This code will run for 15 seconds and when I examine the > time span, it tells me that no time passed. > > Here's my actual code 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 > > Test_Dur : constant := 100_000; Test_Dur : constant := 10_000; -- 100_000 overflows on a 32-bit machine > -- We require the input/output for Duration > package Duration_IO is new Fixed_IO (Duration); > use Duration_IO; > > > Start_Time : Time; > End_Time : Time; > Is_Even : Boolean; > Is_Odd : Boolean; > Junk : Positive; > Junk_In : Natural := 0; > > begin -- Conditional_test delay 0.0; -- Wake up that dozing Ada RTL! > Put_Line ("---Starting per-branch assignment test---"); > > Start_Time := Clock; > for I in 1 .. Test_Dur loop > if I rem 2 = 1 then > Is_Odd := True; > else > Is_Even := True; > end if; > > if Is_Even then > for J in reverse 1 .. Test_Dur loop > Junk_In := Junk_In + 1; > end loop; > Junk := I; > elsif Is_Odd then > for J in reverse 1 .. Test_Dur loop > Junk_In := Junk_In + 1; > end loop; > Junk := I; > end if; > > Is_Even := False; > Is_Odd := False; > end loop; > End_Time := Clock; > > Put ("Assignment within each branch took "); > Put (To_Duration (End_Time - Start_Time), 1, 12, 0); > New_Line (2); > > > Put_Line ("---Starting combined-branch assignment test---"); > > Start_Time := Clock; > for I in 1 .. Test_Dur loop > if I rem 2 = 1 then > Is_Odd := True; > else > Is_Even := True; > end if; > > if Is_Even then > for J in reverse 1 .. Test_Dur loop > Junk_In := Junk_In + 1; > end loop; > elsif Is_Odd then > for J in reverse 1 .. Test_Dur loop > Junk_In := Junk_In + 1; > end loop; > end if; > > if Is_Even or Is_Odd then > Junk := I; > end if; > > Is_Even := False; > Is_Odd := False; > end loop; > End_Time := Clock; > > Put ("Assignment outside of the branching took "); > Put (To_Duration (End_Time - Start_Time), 1, 12, 0); > New_Line (2); > > end Conditional_Test; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de