"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. 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. -- --------------------------------------------------------- J-P. Rosen (rosen@adalog.fr) Visit Adalog's web site at http://www.adalog.fr