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,start X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!c37g2000prb.googlegroups.com!not-for-mail From: deadlyhead Newsgroups: comp.lang.ada Subject: Timing code blocks Date: Thu, 4 Mar 2010 22:34:47 -0800 (PST) Organization: http://groups.google.com Message-ID: <2d5bead9-72f9-4c84-9ac1-a058c2591ef1@c37g2000prb.googlegroups.com> NNTP-Posting-Host: 216.57.220.9 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1267770887 21541 127.0.0.1 (5 Mar 2010 06:34:47 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 5 Mar 2010 06:34:47 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: c37g2000prb.googlegroups.com; posting-host=216.57.220.9; posting-account=snJuNwoAAABnc8T9lYkBlDQrDdSjOjG2 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; 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:9411 Date: 2010-03-04T22:34:47-08:00 List-Id: 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 ---------------------------------------------------------------------- -- 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; -- 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 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; ---------------------------------------------------------------------- The output of this code is as follows: ---Starting per-branch assignment test--- Assignment within each branch took 0.000000000000 ---Starting combined-branch assignment test--- Assignment outside of the branching took 0.000000000000 Why wouldn't any time passage be registered? I know the code above is convoluted, but I've been trying to find a way to get _some_ timing to happen. I originally ran a test with delay statements instead of multiple loops, and the timing worked then, but I felt that there was a real possibility that the delay statements could be introducing inaccuracies into the timing, with the overhead of switching processes in the OS and there being no guarantee of consistently resuming the code. (Ada does not guarantee that code will resume exactly delay_time from now, it guarantees that the code will sleep for _at least_ delay_time.) Anyway, if I'm missing something here, I'd like to know it. I've read section D.8 of the ARM several times and I'm just about convinced that something's broken in my compilers (I'm using GNAT on windows, both the AdaCore binary and a cygwin binary, both with the same output). Is there something that I'm missing, like the real-time clock doesn't advance unless the program delays at some point? I appreciate any insight. This is baffling me.