comp.lang.ada
 help / color / mirror / Atom feed
* Is there an Ada compiler whose Ada.Numerics.Generic_Elementary_Functions.Log(Base=>10, X=>variable) is efficient?
@ 2010-02-15 10:58 Colin Paul Gloster
  2010-02-15 13:02 ` John B. Matthews
                   ` (4 more replies)
  0 siblings, 5 replies; 21+ messages in thread
From: Colin Paul Gloster @ 2010-02-15 10:58 UTC (permalink / raw)


Hello,

I have been improving a program by suppressing C++ in it. After
speeding it up a lot by making changes, I have found one considerable
part which calls a library routine, which is unfortunately very slow
as provided as standard with a number of Ada compilers but which is
very fast with implementations of other languages. For some Ada
compilers perhaps I shall simply need to not rely on an implementation
of this routine by an Ada vendor. Perhaps this post will motivate Ada
vendors to speed up their implementations or for people to report
timings for efficient implementations which are used by default by
other Ada compilers.

At present the routine (which is still being called by a C++ part of
the code) takes up maybe approximately one per cent of the running
time. (I have profiled it but I do not have the timing profiles
available where I am typing this.) This might not sound as if it is
much and it is certainly much less than much of the C++ overhead which
I have removed, but it is trivial to speed it up and speeding up this
one per cent or so would reduce running time by hours.

To contrast different implementations, I have produced the C++ program
#include<iostream>
#include<cmath>
int main()
{
   double answer = 0.0;
   for(int I=1; I<=1000000; ++I)
   {
     #include"body_in_CPlusPlus.cc"
   }
   std::cout << answer;
}
where  body_in_CPlusPlus.cc  contained
answer += std::log10(0.10000000000000000000
);
/*Lines produced by
for((i=1; i<=500; ++i)) do echo -n 'answer += std::log10(0' ; echo  "$i/10" | bc -l ; echo ');'; done
*/
answer += std::log10(050.00000000000000000000
);
and the Ada program
with Ada.Numerics.Generic_Elementary_Functions;
with Interfaces.C;
with Ada.Text_IO;
procedure Logarithmic_Work_In_Ada is
    answer : Interfaces.C.double := 0.0;
    package double_library is new Ada.Numerics.Generic_Elementary_Functions(Interfaces.C.double);
    package double_output_library is new Ada.Text_IO.Float_IO(Interfaces.C.double);
begin

    for I in 1 .. 1_000_000 loop --I would not have this loop but one compiler crashed if
                                 --the source file was sized a few megabytes.

answer := Interfaces.C."+"(answer, double_library.log(0.10000000000000000000
, 10.0 ));
--Lines produced by
--for((i=1; i<=500; ++i)) do echo -n 'answer := Interfaces.C."+"(answer, double_library.log(0' ; echo  "$i/10" | bc -l ; echo ', 10.0 ));'; done
answer := Interfaces.C."+"(answer, double_library.log(050.00000000000000000000
, 10.0 ));


    end loop;

    double_output_library.Put(answer);
end;

The aforementioned code which I have been speeding up did not consist
of merely 500 million calls to std::log10() as consecutive calls, but
instead it consisted of hundreds of times as many calls to
std::log10() interspersed across maybe 200 other functions.

Of the two programs shown, the fastest C++ implementation on one test
platform took less than one millisecond and the fastest Ada
implementation took one minute and 31 seconds and 874 milliseconds on
the same platform. Both g++ and gnatmake were from the same
installation of GCC 4.1.2 20080704 (Red Hat 4.1.2-44).

  g++ -O3 -ffast-math logarithmic_work_in_CPlusPlus.cc -o logarithmic_work_in_CPlusPlus_with_-ffast-math

time ./logarithmic_work_in_CPlusPlus_with_-ffast-math
6.34086e+08
real    0m0.005s
user    0m0.000s
sys     0m0.000s


  g++ -O3 logarithmic_work_in_CPlusPlus.cc -o logarithmic_work_in_CPlusPlus

time ./logarithmic_work_in_CPlusPlus
6.34086e+08
real    0m46.443s
user    0m46.435s
sys     0m0.000s


gnatmake -O3 -ffast-math logarithmic_work_in_Ada.adb -o logarithmic_work_in_Ada_compiled_by_GNAT_with_-ffast-math
(which did
gcc -c -O3 -ffast-math logarithmic_work_in_Ada.adb
logarithmic_work_in_Ada.adb:4:11: warning: file name does not match unit name, should be "logarithmic_work_in_ada.adb"
gnatbind -x logarithmic_work_in_Ada.ali
gnatlink logarithmic_work_in_Ada.ali -ffast-math -o logarithmic_work_in_Ada_compiled_by_GNAT_with_-ffast-mat
whereas trying  -cargs  resulted in no compilation)

time ./logarithmic_work_in_Ada_compiled_by_GNAT_with_-ffast-math
  6.34086408536266E+08

real    1m31.879s
user    1m31.874s
sys     0m0.000s



  gnatmake -O3 logarithmic_work_in_Ada.adb -o logarithmic_work_in_Ada_compiled_by_GNAT

time ./logarithmic_work_in_Ada_compiled_by_GNAT
  6.34086408536266E+08

real    1m33.338s
user    1m33.338s
sys     0m0.000s


proprietary_compiler -O -m logarithmic_work_in_Ada.adb -o logarithmic_work_in_Ada_compiled_by_a_proprietary_compiler

time ./logarithmic_work_in_Ada_compiled_by_a_proprietary_compiler
  6.34086408605593E+08
real    1m41.966s
user    1m41.954s
sys     0m0.000s



^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2010-02-24 10:07 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-15 10:58 Is there an Ada compiler whose Ada.Numerics.Generic_Elementary_Functions.Log(Base=>10, X=>variable) is efficient? Colin Paul Gloster
2010-02-15 13:02 ` John B. Matthews
2010-02-15 14:17   ` Colin Paul Gloster
2010-02-15 17:19     ` John B. Matthews
2010-02-15 14:54 ` jonathan
2010-02-15 15:04   ` jonathan
2010-02-15 19:50     ` sjw
2010-02-16 16:50       ` Colin Paul Gloster
2010-02-15 18:26 ` (see below)
2010-02-15 18:51   ` jonathan
2010-02-15 20:00   ` sjw
2010-02-15 21:17     ` jonathan
2010-02-16  0:09       ` jonathan
2010-02-16 17:33   ` Colin Paul Gloster
2010-02-24 10:07     ` Colin Paul Gloster
2010-02-15 23:04 ` Jeffrey R. Carter
2010-02-16 14:54   ` Colin Paul Gloster
2010-02-16 15:24     ` Colin Paul Gloster
2010-02-16 19:01     ` Jeffrey R. Carter
2010-02-17 10:25       ` Colin Paul Gloster
2010-02-15 23:20 ` Randy Brukardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox