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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,35ed85a9d92a025 X-Google-Attributes: gid103376,public From: Jean-Pierre Rosen Subject: Re: Ada-95 for numerics? Date: 1996/04/02 Message-ID: <199604021629.SAA00724@email.enst.fr>#1/1 X-Deja-AN: 145457993 sender: Ada programming language x-sender: rosen@email.enst.fr comments: Gated by NETNEWS@AUVM.AMERICAN.EDU content-type: text/plain; charset="us-ascii" mime-version: 1.0 newsgroups: comp.lang.ada x-mailer: Windows Eudora Light Version 1.5.2 Date: 1996-04-02T00:00:00+00:00 List-Id: At 08:28 02/04/1996 GMT, you wrote: >[...] So I started coding some of _my_ problems in Ada-95 and check >for the speed. Yet, I am still a beginner in Ada-95, so maybe the coding style >is somewhat unlucky... Something you have to remember is that Ada has nice facilities for dealing with arrays globally. For example, a typical benchmark trap is to translate: DO 10 I=1,N DO 10 J=1,N 10 A(I,J) = B(I,J) into: for I in 1..N loop for J in 1..N loop A(I,J) := B(I,J) end loop; end loop; The correct translation is of course (assuming N is the size of the array): A := B; It is important, because since the compiler KNOWS that global assignment is available, it will not spend a huge time trying to unwind loops, the way the FORTRAN compiler does. And your FORTRAN might look faster... In the same vein, you wrote : > function Unit (n : Integer) return Matrix is > C : Matrix (1..N, 1..N); > begin > for i in C'range(1) loop > for j in C'first(2)..i loop > C(i,j) := 0.0; > C(j,i) := 0.0; > end loop; > C(i,i) := 1.0; > end loop; > return (C); > end Unit; This should be: function Unit (n : Integer) return Matrix is C : Matrix (1..N, 1..N) := (Others => (Others => 0.0)); begin for i in C'range(1) loop C(i,i) := 1.0; end loop; return (C); end Unit; If the compiler is not very clever, generated code will be the same as with what you wrote. But it is much easier for the compiler to recognize that a simple "move byte string" instruction is enough to do the trick. Can't be worse, likely to be better.... +------------------------------------o-------------------------------------+ | P-mail: | E-mail: rosen@enst.fr | | ADALOG - 27 avenue de Verdun | Tel: +33 1 46 45 51 12 | | 92170 Vanves - FRANCE | Fax: +33 1 46 45 52 49 | +------------------------------------o-------------------------------------+