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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC,T_FILL_THIS_FORM_SHORT autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder.news-service.com!188.40.43.213.MISMATCH!feeder.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Colin Paul Gloster Newsgroups: comp.lang.ada Subject: Re: Is there an Ada compiler whose Ada.Numerics.Generic_Elementary_Functions.Log(Base=>10, X=>variable) is efficient? Date: Tue, 16 Feb 2010 17:33:44 +0000 Organization: A noiseless patient Spider Message-ID: References: Reply-To: Colin Paul Gloster Mime-Version: 1.0 Content-Type: TEXT/PLAIN; format=flowed; charset=US-ASCII Injection-Date: Tue, 16 Feb 2010 17:36:02 +0000 (UTC) Injection-Info: feeder.eternal-september.org; posting-host="kheEuXGHhE2Z5eF1gAST+A"; logging-data="26247"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+UPlIVTBV9Hw7yMdyEYKKCpAkAxOJDG2mL4BSNKAB5cA==" User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) In-Reply-To: Cancel-Lock: sha1:cWsUjo005WRaPWoTrFwZWZmIY7c= X-X-Sender: Colin_Paul@Bluewhite64.example.net Xref: g2news1.google.com comp.lang.ada:9269 Date: 2010-02-16T17:33:44+00:00 List-Id: On Mon, 15 Feb 2010, William Findlay posted: |------------------------------------------------------------------------| |"On 15/02/2010 10:58, in article | |alpine.LNX.2.00.1002151055530.17315@Bluewhite64.example.net, "Colin Paul| |Gloster" wrote: | | | |> 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). | | | |Is that 1 millisecond for 1e6 calls?" | |------------------------------------------------------------------------| No, that was less than one millisecond for 500 * 10**6 C++ calls. |------------------------------------------------------------------------| |" This implies 1ns per call in C++. | |I find it incredible that a log function could be so fast. | |I think the loop body must be evaluated at compile-time in C++." | |------------------------------------------------------------------------| The C++ compiler did manage to eliminate almost everything. |------------------------------------------------------------------------| |"On my system your Ada code gives: | | | |6.34086408536266E+08 | | | |real 0m33.918s | |user 0m33.864s | |sys 0m0.025s | | | |And your original C++ code gives: | | | |6.34086e+08 | |real 0m0.110s | |user 0m0.003s | |sys 0m0.003s | | | |But if I replace the C++ loop body by: | | | | for(int j=1; j<=500; ++j) | | answer += std::log10(j*0.100000000000000000000); | |It now gives: | | | |6.34086e+08 | |real 0m18.112s | |user 0m18.082s | |sys 0m0.015s | | | |This less than twice as fast as the more generalized Ada code. | | | |[..]" | |------------------------------------------------------------------------| Thank you for exposing this flaw in the C++ code. with Ada.Numerics.Generic_Elementary_Functions; with Interfaces.C; with Ada.Text_IO; procedure Logarithmic_Work_In_Ada_with_a_Findlay_loop 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 for J in 1 .. 500 loop answer := Interfaces.C."+"( answer, double_library.log( Interfaces.C."*"( Interfaces.C.double(J), 0.100000000000000000000 ) , 10.0 ) ); end loop; end loop; double_output_library.Put(answer); end; gnatmake -O3 -ffast-math Logarithmic_Work_In_Ada_with_a_Findlay_loop.adb -o Logarithmic_Work_In_Ada_with_a_Findlay_loop_compiled_by_GCC4.4.3_with_-ffast-math time ./Logarithmic_Work_In_Ada_with_a_Findlay_loop_compiled_by_GCC4.4.3_with_-ffast-math 6.34086408606382E+08 real 0m31.091s user 0m31.090s sys 0m0.004s time ./Logarithmic_Work_In_Ada_with_a_Findlay_loop_compiled_by_GCC4.4.3_with_-ffast-math 6.34086408606382E+08 real 0m31.094s user 0m31.094s sys 0m0.004s gnatmake -O3 Logarithmic_Work_In_Ada_with_a_Findlay_loop.adb -o Logarithmic_Work_In_Ada_with_a_Findlay_loop_compiled_by_GCC4.4.3 6.34086408606382E+08 real 0m31.388s user 0m31.378s sys 0m0.008s g++ -O3 -ffast-math logarithmic_work_in_CPlusPlus_with_a_Findlay_loop.cc -o logarithmic_work_in_CPlusPlus_with_a_Findlay_loop_compiled_by_GCC4.4.3_with_-ffast-math time ./logarithmic_work_in_CPlusPlus_with_a_Findlay_loop_compiled_by_GCC4.4.3_with_-ffast-math 6.34086e+08 real 0m38.388s user 0m38.390s sys 0m0.000s time ./logarithmic_work_in_CPlusPlus_with_a_Findlay_loop_compiled_by_GCC4.4.3_with_-ffast-math 6.34086e+08 real 0m38.547s user 0m38.546s sys 0m0.000s g++ -O3 logarithmic_work_in_CPlusPlus_with_a_Findlay_loop.cc -o logarithmic_work_in_CPlusPlus_with_a_Findlay_loop_compiled_by_GCC4.4.3 time ./logarithmic_work_in_CPlusPlus_with_a_Findlay_loop_compiled_by_GCC4.4.3 6.34086e+08 real 0m38.428s user 0m38.426s sys 0m0.004s with Ada.Numerics.Generic_Elementary_Functions; with Interfaces.C; with Ada.Text_IO; procedure Logarithmic_Work_In_Ada_with_a_Findlay_loop_with_a_Parker_GNATism is Log_Base_10_Of_The_Base_Of_The_Natural_Logarithm : constant Interfaces.C.Double := 0.434_294_481_903_251_827_651_129; 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 for J in 1 .. 500 loop answer := Interfaces.C."+" ( answer, Interfaces.C."*" ( double_library.Log ( Interfaces.C."*" ( Interfaces.C.double(J), 0.100000000000000000000 ) ) , Log_Base_10_Of_The_Base_Of_The_Natural_Logarithm ) ); end loop; end loop; double_output_library.Put(answer); end; gnatmake -O3 -ffast-math Logarithmic_Work_In_Ada_with_a_Findlay_loop_with_a_Parker_GNATism_compiled_by_GCC4.4.3_with_-ffast-math.adb -o Logarithmic_Work_In_Ada_with_a_Findlay_loop_with_a_Parker_GNATism_compiled_by_GCC4.4.3_with_-ffast-math time ./Logarithmic_Work_In_Ada_with_a_Findlay_loop_with_a_Parker_GNATism_compiled_by_GCC4.4.3_with_-ffast-math 6.34086408606382E+08 real 0m14.434s user 0m14.433s sys 0m0.004s -bash bluewhite64 /home/Colin_Paul/logarithms $ -bash bluewhite64 /home/Colin_Paul/logarithms $ gnatmake -O3 Logarithmic_Work_In_Ada_with_a_Findlay_loop_with_a_Parker_GNATism.adb -o Logarithmic_Work_In_Ada_with_a_Findlay_loop_with_a_Parker_GNATism_compiled_by_GCC4.4.3 time ./Logarithmic_Work_In_Ada_with_a_Findlay_loop_with_a_Parker_GNATism_compiled_by_GCC4.4.3 6.34086408606382E+08 real 0m14.450s user 0m14.453s sys 0m0.000s