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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,13280cdb905844e4 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!15g2000yqa.googlegroups.com!not-for-mail From: jonathan 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 07:04:25 -0800 (PST) Organization: http://groups.google.com Message-ID: References: <7b3d1a4c-e61f-41c0-a35b-a9d13c6f4f67@j31g2000yqa.googlegroups.com> NNTP-Posting-Host: 143.117.23.62 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1266246265 31106 127.0.0.1 (15 Feb 2010 15:04:25 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 15 Feb 2010 15:04:25 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: 15g2000yqa.googlegroups.com; posting-host=143.117.23.62; posting-account=Jzt5lQoAAAB4PhTgRLOPGuTLd_K1LY-C User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.16) Gecko/2009121609 Iceweasel/3.0.6 (Debian-3.0.6-3),gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:9237 Date: 2010-02-15T07:04:25-08:00 List-Id: On Feb 15, 2:54=A0pm, jonathan wrote: > On Feb 15, 10:58=A0am, Colin Paul Gloster > wrote: > > > 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.... > > Here is my own bench ... easier to play with: > > with ada.numerics.generic_elementary_functions; > with text_io; use text_io; > > procedure log_bench is > > =A0 type Real is digits 15; > =A0 package Math is new ada.numerics.generic_elementary_functions > (Real); > =A0 use Math; > =A0 x, y : Real :=3D 0.1; > > =A0 -- might (or might not!) be faster to use: > =A0 -- =A0 =A0log_base_10 (x) =3D log_base_10_of_e * log_base_e (x) > > =A0 Log_base_10_of_e : constant :=3D 0.434_294_481_903_251_827_651_129; > > begin > > =A0 for i in 1 .. 1_000_000 loop > =A0 =A0 x :=3D x + Log_base_10_of_e * Log (y); > =A0 =A0 y :=3D y + 0.0000000000001; > =A0 end loop; > =A0 put (Real'Image(x)); > > > > gnatmake =A0gnatnp -O2 -march=3Dnative log_bench.adb Opps, accidently hit the send button! Continuing discussion: gnatmake gnatnp -O2 -march=3Dnative log_bench.adb -9.99999682845800E+05 real 0m0.024s user 0m0.024s sys 0m0.000s NOW, comment out the y :=3D y + ... so that the inner loop is constant, and use the same compilation switches: gnatmake gnatnp -O2 -march=3Dnative log_bench.adb -9.99999900000000E+05 real 0m0.002s user 0m0.000s sys 0m0.000s You see now what's happening. With the gnatn switch the compiler is smart enough to call the Log just once, rather than 10**6 times. If you remove the -gnatn or -gnatN switches, then it runs in 0m0.024s again. Jonathan