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,e7e6e919cef50811 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-03-14 03:14:19 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news-han1.dfn.de!news.fh-hannover.de!news.uni-stuttgart.de!nntp.cs.uni-magdeburg.de!news.cs.uni-magdeburg.de!not-for-mail From: Gerald Kasner Newsgroups: comp.lang.ada Subject: Re: comparing gnat/Ada95 and g77 Date: Thu, 14 Mar 2002 12:14:31 +0100 Organization: Uni Magdeburg Message-ID: <3C908617.C96A6579@Physik.Uni-Magdeburg.DE> References: NNTP-Posting-Host: kasner.nat.uni-magdeburg.de Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: graf.cs.uni-magdeburg.de 1016104457 1328 141.44.40.12 (14 Mar 2002 11:14:17 GMT) X-Complaints-To: abuse@cs.uni-magdeburg.de NNTP-Posting-Date: Thu, 14 Mar 2002 11:14:17 +0000 (UTC) X-Mailer: Mozilla 4.78 [de] (X11; U; Linux 2.4.9-13smp i686) X-Accept-Language: en Xref: archiver1.google.com comp.lang.ada:21212 Date: 2002-03-14T12:14:31+01:00 List-Id: Reinert Korsnes schrieb: > > Hi, > > Could anybody try these two programs (Ada and Fortran) > and see if it is possible to make the Ada version (via compile > options) to run as fast as the Fortran version under Linux, gnat > and g77 ? > > reinert > > -------------------------------------------------------------------- > with Ada.Numerics.Generic_Elementary_Functions,Text_IO; > use Text_IO; > procedure test1 is > type Real is Digits 9; > package Flt_Io is new Text_IO.Float_Io (Real); > package Int_Io is new Text_IO.Integer_Io (Integer); > package E_F is new Ada.Numerics.Generic_Elementary_Functions (Real); > > use E_F,Flt_Io,Int_Io; > > N : Integer := 10_000_000; > M : Integer := N/50; > x : Real := 10.0; > begin > for I in 1 .. N loop > x := x + Real(I)/Real(N); > x := x*0.5 + 1.0 + sin(x)*cos(x) + sin(x) + cos(x) + > sin(x)*sin(x) + cos(x)*cos(x); > if I mod M = 0 then > Put(I); Put (x,4,7,0); New_Line (1); > end if; > end loop; > end; > ------------------------------------------------------------------------ Dear Reinert, the difference is small on my machines ~ 28 sec for g77 (with -O3 option) ~ 32 sec for gnat (with -O3 -gnatp option) The difference seems to be in the trigonometric functions, look in a-ngelfu.adb, Ada is more careful in these cases. Rather than playing with options, it seems to be better to rewrite the program (as below). The program below needs about 11 sec, three times faster than the original one. It's the algorithm, not the language that matters. -Gerald ############################################################################## with Ada.Numerics.Generic_Elementary_Functions,Text_IO; use Text_IO; procedure test2 is type Real is Digits 9; package Flt_Io is new Text_IO.Float_Io (Real); package Int_Io is new Text_IO.Integer_Io (Integer); package E_F is new Ada.Numerics.Generic_Elementary_Functions (Real); use E_F,Flt_Io,Int_Io; N : Integer := 10_000_000; M : Integer := N/50; x : Real := 10.0; c, s : Real; begin for I in 1 .. N loop x := x + Real(I)/Real(N); c :=cos(x); s :=sin(x); x := x*0.5 + 1.0 + s*(c+1.0+s) +c*(1.0+c); if I mod M = 0 then Put(I); Put (x,4,7,0); New_Line (1); end if; end loop; end;