From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Timing code blocks
Date: Fri, 5 Mar 2010 08:55:19 +0100
Date: 2010-03-05T08:55:17+01:00 [thread overview]
Message-ID: <13j6juslcud2k.1n4jnpj74p3k$.dlg@40tude.net> (raw)
In-Reply-To: 2d5bead9-72f9-4c84-9ac1-a058c2591ef1@c37g2000prb.googlegroups.com
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
next prev parent reply other threads:[~2010-03-05 7:55 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 [this message]
2010-03-05 8:16 ` deadlyhead
2010-03-05 8:49 ` Dmitry A. Kazakov
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