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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,101c38a932801b81 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!news.glorb.com!newscon02.news.prodigy.net!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Semantics of statement reordering relevant to Ada.Real_Time Date: Sun, 30 Mar 2008 14:59:21 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls6.std.com 1206903561 22366 192.74.137.71 (30 Mar 2008 18:59:21 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Sun, 30 Mar 2008 18:59:21 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:JZcqvCoQTzYGPcejQ07oaBX/68w= Xref: g2news1.google.com comp.lang.ada:20645 Date: 2008-03-30T14:59:21-04:00 List-Id: Eric Hughes writes: > On Mar 29, 7:51 am, kongra wrote: >> Start_T := Ada.Real_Time.Clock; >> for K in 1 .. 10 loop >> for I in 1 .. 10_000_000 loop >> Val := Val + I; >> end loop; >> end loop; >> End_T := Ada.Real_Time.Clock; > > I have a question about this piece of the program. Because the middle > uses only variables 'K', 'I', and 'Val', and the side-effects of > modifying these variables are entirely local, and because there's no > inter-dependency of these variables upon either the first or last > statements, aren't the following reorderings legal for code > generation? To wit: > > Long_Statement ; > Start_T := Ada.Real_Time.Clock ; > End_T := Ada.Real_Time.Clock ; > > Start_T := Ada.Real_Time.Clock ; > End_T := Ada.Real_Time.Clock ; > Long_Statement ; > > Irrelevant to the quirks mentioned earlier, isn't it legal operation > for the interval to come out zero? Yes. For example, I can calculate the final value of Val with pencil and paper, so I guess I could teach an optimizer to do it at compile time. ;-) >...It seems that for known-correct > operation for all possible compilers you'd need to manually serialize > these operations in the order desired. The only thing that's guaranteed is I/O behavior, so you have to do some I/O. And you should inspect the generated machine code to see if you're measuring what you think you're measuring. In other words, this sort of thing is pretty much outside the language definition. Also, it might be better to measure using outside tools, like the Unix 'time' command, or perhaps a stopwatch. - Bob