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-7-bit X-Google-Thread: 103376,38fc011071df5a27 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-06-09 12:50:51 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news-out.visi.com!petbe.visi.com!uunet!ash.uu.net!spool.news.uu.net!not-for-mail Date: Mon, 09 Jun 2003 15:49:20 -0400 From: Hyman Rosen User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.5a) Gecko/20030529 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Ideas for Ada 200X References: <1055177817.528719@master.nyc.kbcfp.com> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Organization: KBC Financial Products Message-ID: <1055188160.904315@master.nyc.kbcfp.com> Cache-Post-Path: master.nyc.kbcfp.com!unknown@nightcrawler.nyc.kbcfp.com X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/) NNTP-Posting-Host: 204.253.250.10 X-Trace: 1055188161 26251 204.253.250.10 Xref: archiver1.google.com comp.lang.ada:38875 Date: 2003-06-09T15:49:20-04:00 List-Id: tmoran@acm.org wrote: > Regardless, given your templates, could you use them to write a > piece of code to "A = A+B;" and a piece to "A += B;" to show us > how those look when you use the templates, and also how fast do > they execute 10**7 times on 3x3 matrices of zeros? I noticed an error in my previous posting; change M to N. For A += B, we need to add to Matrix template Matrix &operator+=(const T &r) { for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) data[i][j] += r(i,j); return *this; } Having done that, we can do (warning - this is not exactly the code that I compiled, so it may have errors) #include #include #include int main() { Matrix<3> A, B; int i, j; for (i = 0; i < 3; ++i) for (j = 0; j < 3; ++j) A.data[i][j] = B.data[i][j] = 0; long t1b = time(0); for (i = 0; i < 100000000; ++i) A = A + B; long t1e = time(0); std::cout << "+ " << t1e - t1b << '\n'; long t2b = time(0); for (i = 0; i < 100000000; ++i) A += B; long t2e = time(0); std::cout << "+= " << t2e - t2b << '\n'; } On my Sun workstation, using g++.5.8 (GCC) 3.2.2 and compiling with -O6, I get 11 seconds for "+" and 7 seconds for "+=". Notice that this is for one hundred million (10**8) iterations.