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=-0.0 required=5.0 tests=BAYES_00, FILL_THIS_FORM_FRAUD_PHISH,REPLYTO_WITHOUT_TO_CC, T_FILL_THIS_FORM_SHORT autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,13280cdb905844e4,start X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!news.glorb.com!newsfeed.straub-nv.de!feeder.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Colin Paul Gloster Newsgroups: comp.lang.ada Subject: Is there an Ada compiler whose Ada.Numerics.Generic_Elementary_Functions.Log(Base=>10, X=>variable) is efficient? Date: Mon, 15 Feb 2010 10:58:03 +0000 Organization: A noiseless patient Spider Message-ID: Reply-To: Colin Paul Gloster Mime-Version: 1.0 Content-Type: TEXT/PLAIN; format=flowed; charset=US-ASCII Injection-Date: Mon, 15 Feb 2010 11:00:19 +0000 (UTC) Injection-Info: feeder.eternal-september.org; posting-host="kheEuXGHhE2Z5eF1gAST+A"; logging-data="11914"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18K7Yb0S4SfikVKxRqvXtoTnACL9dqK3anqlyjhRnb2eg==" User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) Cancel-Lock: sha1:2t9gRntsoMEFevEyXWVdFyGp3S0= X-X-Sender: Colin_Paul@Bluewhite64.example.net Xref: g2news1.google.com comp.lang.ada:9220 Date: 2010-02-15T10:58:03+00:00 List-Id: 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 #include 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