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-Thread: 103376,703c4f68db81387d X-Google-Thread: 115aec,703c4f68db81387d X-Google-Thread: f43e6,703c4f68db81387d X-Google-Attributes: gid103376,gid115aec,gidf43e6,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!proxad.net!teaser.fr!news.wanadoo.fr!news.wanadoo.fr!not-for-mail Sender: obry@PASCAL Newsgroups: comp.lang.ada,comp.realtime,comp.software-eng Subject: Re: Teaching new tricks to an old dog (C++ -->Ada) References: <4229bad9$0$1019$afc38c87@news.optusnet.com.au> <1110032222.447846.167060@g14g2000cwa.googlegroups.com> <871xau9nlh.fsf@insalien.org> <3SjWd.103128$Vf.3969241@news000.worldonline.dk> <87r7iu85lf.fsf@insalien.org> <1110052142.832650@athnrd02> <1110284070.410136.205090@o13g2000cwo.googlegroups.com> <395uqaF5rhu2mU1@individual.net> <112rs0bdr2aftdf@corp.supernews.com> <1inxxr988rxgg$.1w9dedak41k89.dlg@40tude.net> <112s1r0rf0o8nca@corp.supernews.com> <112sonip5v4dca6@corp.supernews.com> <112t3de6fu04f38@corp.supernews.com> <112u7undo5h2q0a@corp.supernews.com> From: Pascal Obry Organization: Home - http://www.obry.net User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 Date: 09 Mar 2005 17:33:38 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii NNTP-Posting-Date: 09 Mar 2005 17:33:40 CET NNTP-Posting-Host: 82.120.30.69 X-Trace: 1110386020 news.wanadoo.fr 851 82.120.30.69:2393 X-Complaints-To: abuse@wanadoo.fr Xref: g2news1.google.com comp.lang.ada:8946 comp.realtime:1137 comp.software-eng:4695 Date: 2005-03-09T17:33:40+01:00 List-Id: CTips writes: > I can't think of anyone submitting code to a performance site without first > making sure I was getting as much performance out of it. It appears that the > Ada mindset is different. Or is it because GNAT is known to produce buggy > code at higher optimization levels? You amused me :) > BTW: any chance someone might be tempted into actually submitting a run with > appropriate optimization parameters? With a code far closer (not yet identical as in C the array is allocated) to the C equivalent: << with Text_IO, Ada.Command_Line; procedure Matrix is use Ada; Size : constant Natural := 30; type Int is new Integer; type Int_Matrix is array (1 .. Size, 1 .. Size) of Int; procedure Mk_Matrix (NRows, NCols : Natural; M : out Int_Matrix) is Count : Int := 1; begin for I in M'Range (1) loop for J in M'Range (2) loop M (I, J) := Count; Count := Count + 1; end loop; end loop; end Mk_Matrix; procedure M_Mult (M1, M2 : Int_Matrix; MM : in out Int_Matrix) is Sum : Int; begin for I in M1'Range (1) loop for J in M2'Range (2) loop Sum := 0; for KK in M1'Range (2) loop Sum := Sum + M1 (I, KK) * M2 (KK, J); end loop; MM (I, J) := Sum; end loop; end loop; end M_Mult; M1, M2, MM : Int_Matrix; N : Positive := 1; begin begin N := Positive'Value (Ada.Command_Line.Argument (1)); exception when Constraint_Error => null; end; Mk_Matrix (Size, Size, M1); Mk_Matrix (Size, Size, M2); for Iter in 1 .. N loop M_Mult (M1, M2, MM); end loop; Text_IO.Put_Line (Int'Image (MM (1, 1)) & Int'Image (MM (3, 4)) & Int'Image (MM (4, 3)) & Int'Image (MM (5, 5))); end Matrix; >> compiled for the C code using: $ gcc -o c_matrix -O2 matrix.c compiled for the Ada code using: $ gnatmake -f -O2 -gnatp matrix.adb -bargs -static (-bargs -static to use the static runtime, this is what C does in this case). I get: $ time matrix 100 270165 1061760 1453695 1856025 real 0m0.033s user 0m0.010s sys 0m0.020s $ time c_matrix 100 270165 1061760 1453695 1856025 real 0m0.033s user 0m0.010s sys 0m0.010s I see identical results here, this is on a Windows box using GCC 3.4.4 and GNAT 5.03a. Of course this is no surprise since GNAT share the very same backend! Yet this means just nothing. A good benchmark is done on real applications. At least I hope it will dismiss the idea that Ada is inherently slow. There is nothing in Ada that is designed to be slow, a good compiler for Ada as a good compiler for any language should generate good code, that's all. Pascal. -- --|------------------------------------------------------ --| Pascal Obry Team-Ada Member --| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE --|------------------------------------------------------ --| http://www.obry.org --| "The best way to travel is by means of imagination" --| --| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595