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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,38fc011071df5a27 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-06-04 03:11:34 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!newsfeed.online.be!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed1.e.nsc.no!nsc.no!nextra.com!uio.no!193.216.69.35.MISMATCH!dax.net!juliett.dax.net!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Ideas for Ada 200X References: From: Ole-Hjalmar Kristensen Message-ID: <7vu1b640gf.fsf@vlinux.voxelvision.no> User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Wed, 04 Jun 2003 10:10:57 GMT NNTP-Posting-Host: 193.216.12.150 X-Complaints-To: abuse@tele2.no X-Trace: juliett.dax.net 1054721457 193.216.12.150 (Wed, 04 Jun 2003 12:10:57 MET DST) NNTP-Posting-Date: Wed, 04 Jun 2003 12:10:57 MET DST Organization: Tele2 Norway AS Public Access Xref: archiver1.google.com comp.lang.ada:38579 Date: 2003-06-04T10:10:57+00:00 List-Id: tmoran@acm.org writes: > >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 > > Using > subtype ns is integer range 1 .. 100; -- or 1 .. 5 or 1 .. 50 > type matrices is array(ns,ns) of integer; > procedure add_to(left : in out matrices; right : in matrices) is ... > function "+"(left, right : matrices) return matrices is ... > > and compiling with -O3 -gnato on Windows gnat 3.15p, I find > function "+=" takes about 12% longer than procedure add_to > You mean function "+" ? > inserting "pragma suppress(all_checks)", > function "+=" takes about 35% longer than procedure add_to > > Running a comparison with a program compiled with MSVC++ 5.0 > 10K iterations on a 100x100 matrix the "+=" vs add_to take > 1.17 vs .88 seconds with Ada, 5.3 vs 2.7 seconds with C++ > (It's been a while, and my C is rusty. Please ask tmoran@acm.org > if you would like my code to check or improve or run with your system.) I think the difference between C++ and Ada is the compiler. I run both through gcc, and got identical results. The function "+" is about three times slower on my system, as you can see. This is a bit disappointing, I'll run it through gcc 3.2 later and see if it does any better. procedure Matrix_proc is subtype M_Index is Integer range 1..100; type Matrices is array(M_Index,M_Index) of Integer; procedure add(M1 : in out Matrices; M2: Matrices) is begin for I in M1'Range(2) loop for J in M1'Range(1) loop M1(I,J) := M1(I,J) + M2(I,J); end loop; end loop; end add; pragma Inline(Add); M1 : Matrices ; M2: Matrices ; begin for I in 1..10000 loop Add(M1,M2); end loop; end Matrix_proc; procedure Matrix_fun is subtype M_Index is Integer range 1..100; type Matrices is array(M_Index,M_Index) of Integer; function "+"(M1,M2: Matrices) return Matrices is Tmp : Matrices := M1; begin for I in M1'Range(2) loop for J in M1'Range(1) loop Tmp(I,J) := M1(I,J) + M2(I,J); end loop; end loop; return Tmp; end "+"; pragma Inline("+"); M1 : Matrices ; M2: Matrices ; begin for I in 1..10000 loop M1 := M1 + M2; end loop; end Matrix_fun; inline void add(int m1[100][100], int m2[100][100]) { for(int i = 0; i < 100; i++){ for(int j = 0; j < 100; j++){ m1[i][j] = m1[i][j] + m2[i][j]; } } } int main() { int m1[100][100]; int m2[100][100]; for(int i = 0; i < 10000; i++){ add(m1,m2); } } oleh@VOLGA /cygdrive/c/div $ gnatmake -s -gnatp -O3 -funroll-loops matrix_fun gcc -c -gnatp -O3 -funroll-loops matrix_fun.adb matrix_fun.adb:19:04: warning: "M2" is never assigned a value matrix_fun.adb:22:13: warning: "M1" may be referenced before it has a value gnatbind -x matrix_fun.ali gnatlink matrix_fun.ali oleh@VOLGA /cygdrive/c/div $ gnatmake -s -gnatp -O3 -funroll-loops matrix_proc gcc -c -gnatp -O3 -funroll-loops matrix_proc.adb matrix_proc.adb:16:04: warning: "M2" is never assigned a value gnatbind -x matrix_proc.ali gnatlink matrix_proc.ali oleh@VOLGA /cygdrive/c/div $ !g++ g++ -O3 -funroll-loops -o matrix_c matrix_c.cpp oleh@VOLGA /cygdrive/c/div $ time matrix_c real 0m0.221s user 0m0.200s sys 0m0.020s oleh@VOLGA /cygdrive/c/div $ time matrix_proc real 0m0.215s user 0m0.010s sys 0m0.010s oleh@VOLGA /cygdrive/c/div $ time matrix_fun real 0m0.622s user 0m0.030s sys 0m0.000s oleh@VOLGA /cygdrive/c/div $ -- Ole-Hj. Kristensen ****************************************************************************** * You cannot consistently believe this sentence. ******************************************************************************