From: Gerald Kasner <Gerald.Kasner@Physik.Uni-Magdeburg.DE>
Subject: Re: comparing gnat/Ada95 and g77
Date: Thu, 14 Mar 2002 12:14:31 +0100
Date: 2002-03-14T12:14:31+01:00 [thread overview]
Message-ID: <3C908617.C96A6579@Physik.Uni-Magdeburg.DE> (raw)
In-Reply-To: a6prk9$jhc$1@snipp.uninett.no
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;
next prev parent reply other threads:[~2002-03-14 11:14 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-03-14 9:47 comparing gnat/Ada95 and g77 Reinert Korsnes
2002-03-14 10:37 ` John McCabe
2002-03-14 11:00 ` Preben Randhol
2002-03-15 10:44 ` Reinert Korsnes
2002-03-15 12:14 ` John McCabe
2002-03-15 17:53 ` Georg Bauhaus
2002-03-16 14:00 ` Gautier
2002-03-14 10:58 ` Martin Dowie
2002-03-14 11:04 ` chris.danx
2002-03-14 11:07 ` Bobby D. Bryant
2002-03-14 11:41 ` David C. Hoos, Sr.
2002-03-14 11:06 ` Preben Randhol
2002-03-14 16:43 ` Jeffrey Carter
2002-03-14 11:14 ` Gerald Kasner [this message]
2002-03-14 12:59 ` Gary Scott
2002-03-14 13:17 ` Jean-Marc Bourguet
2002-03-15 0:52 ` Gary Scott
2002-03-14 16:19 ` Dan Andreatta
2002-03-15 9:35 ` Gerald Kasner
2002-03-14 17:31 ` Toshitaka Kumano
2002-03-14 16:40 ` Jeffrey Carter
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox