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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,38fc011071df5a27 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-06-03 12:01:35 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: 18k11tm001@sneakemail.com (Russ) Newsgroups: comp.lang.ada Subject: Re: Ideas for Ada 200X Date: 3 Jun 2003 12:01:34 -0700 Organization: http://groups.google.com/ Message-ID: References: <6a90b886.0305262344.1d558079@posting.google.com> <3ED41344.7090105@spam.com> <3ED46D81.FF62C34F@0.0> <3ED46E07.4340CABC@0.0> <3ED4F3FD.A0EF7079@alfred-hilscher.de> <6vWcnTWjF83bD0qjXTWcpA@gbronline.com> NNTP-Posting-Host: 128.102.146.44 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1054666894 26869 127.0.0.1 (3 Jun 2003 19:01:34 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 3 Jun 2003 19:01:34 GMT Xref: archiver1.google.com comp.lang.ada:38540 Date: 2003-06-03T19:01:34+00:00 List-Id: "Jean-Pierre Rosen" wrote in message news:... > "Russ" <18k11tm001@sneakemail.com> a �crit dans le message news: > bebbba07.0306022127.46f6c998@posting.google.com... > > Wesley Groleau wrote in message > news:... > > > > No, they aren't the same. The result is the same, but the second form > > > > can be implemented much more efficiently. The first form requires the > > > > > > Oh, good grief. If the language specification says > > > they have the same result, then they can be implemented > > > the same way. _I_ certainly will never specify "these > > > must have the same result, but you must do extra work > > > on that one." > > > > Oh, good grief yourself. > > > > If A and B are matrices, then > > > > A := A + B > > and > > A += B > > > > give the same result, but the latter, if properly implemented, is > > indeed substantially more efficient than the former. > > > > Once again, I will explain why. The first form requires the creation > > of a temporary matrix to hold the sum, then a copy from the temporary > > back to A. The second form, on the other hand, can do the addition in > > place in A on an element by element basis, eliminating the need for > > the temporary matrix and the copy operation. > > > My usual answer to things dealing with efficiency: > Did you try to measure which one is faster, before asserting that? > If no, do the measurement and come again. I actually did this test in C++ several years ago. The "+=" form was about three to four times faster. If you're telling me that is not true for Ada, I can only conclude that either 1) you did not implement it properly, or 2) Ada itself does not implement the procedure equivalent to "+=" very efficiently. Perhaps I'll try it myself in Ada when I get a chance. Since you've already done it in Ada, I suggest you try the two forms in C++ and see how it compares with Ada. If your claim is true, then the C++ "+=" form should be substantially faster than the equivalent form in Ada. > It is absolutely not obvious that the extra copy is more costly (and yes, I > did the measurement). > Remember that when accessing an array passed by reference, you need an extra > dereference to > access each element, compared with a local variable. OTOH, copying can be > quite fast (block copy). > On big matrices, having a local copy can be faster. Depends on many things, > including the size of > the matrix. Think of it this way: A := A + B is equivalent to temp := A -- create temp and copy into it temp += B -- perform addition A := temp -- copy back over to A How could that possibly be more efficient that simply A += B? In C++, passing by reference is very efficient. If I understand it correctly, aside from passing the address, it's essentially as efficient as accessing the passed array inline or as a global. In the "+=" form, both matrices are passed by reference (at least in C++), so I don't see how this could be inefficient in any way. Aside from passing the addresses of the arrays, it's as efficient as doing it inline. I assume the same is true for Ada. Am I wrong?