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-10 13:33:22 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!snoopy.risq.qc.ca!chi1.webusenet.com!news.webusenet.com!news-feed01.roc.ny.frontiernet.net!nntp.frontiernet.net!uunet!dca.uu.net!ash.uu.net!spool.news.uu.net!not-for-mail Date: Tue, 10 Jun 2003 16:33:10 -0400 From: Hyman Rosen User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4b) Gecko/20030603 Thunderbird/0.1a 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: <1055277191.38385@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: 1055277191 1944 204.253.250.10 Xref: archiver1.google.com comp.lang.ada:38934 Date: 2003-06-10T16:33:10-04:00 List-Id: tmoran@acm.org wrote: > how fast do they execute 10**7 times on 3x3 matrices of zeros? Here's the fastest I've gotten so far. Program output (times are in seconds): + 8 += 5 Compiler options: g++ -finline-limit=1000 -O3 -funroll-loops Compiler version: g++.5.8 (GCC) 3.2.2 uname -a: SunOS 5.8 Generic_108528-15 sun4u sparc SUNW,Sun-Fire-880 Code: #include #include #include template struct add_op { const L &l; const R &r; add_op(const L &l, const R &r) : l(l), r(r) { } double operator()(int i, int j) const { return l(i,j) + r(i,j); } }; template inline add_op operator+(const L &l, const R &r) { return add_op(l,r); } template struct Matrix { double data[N][N]; 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; } 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; } double operator()(int i, int j) const { return data[i][j]; } }; 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] = 0; B.data[i][j] = 0; } } long t1b = time(0); for (i = 0; i < 100000000; ++i) A = A + B; long t1e = time(0); long t2b = time(0); for (i = 0; i < 100000000; ++i) A += B; long t2e = time(0); std::cout << "+ " << t1e - t1b << '\n'; std::cout << "+= " << t2e - t2b << '\n'; }