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 Path: g2news1.google.com!news1.google.com!news.glorb.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "(see below)" 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: Mon, 15 Feb 2010 18:26:31 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Trace: individual.net /dHPiT+i9+R0qC5gNBIzPAAdDnvK1EiH28hvuHn5hu4GzocLf0 Cancel-Lock: sha1:GXHttVynSFU4s/YhE6hjPbk5PXQ= User-Agent: Microsoft-Entourage/12.20.0.090605 Thread-Topic: Is there an Ada compiler whose Ada.Numerics.Generic_Elementary_Functions.Log(Base=>10, X=>variable) is efficient? Thread-Index: AcqubGUjflrPwrjvvkqlpYjeCU0lKw== Xref: g2news1.google.com comp.lang.ada:9243 Date: 2010-02-15T18:26:31+00:00 List-Id: 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? 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++. 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. The simpler inner loop: for(int j=1; j<=500; ++j) answer += j; gives: 1.2525e+11 real 0m0.677s user 0m0.614s sys 0m0.003s So the difference cannot be due to loop overhead. -- Bill Findlay chez blueyonder.co.uk