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-Thread: 103376,13c7ec19f3c43155 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nlpi057.nbdc.sbc.com!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: speed of generic code in Ada (vs Java) Date: Fri, 23 May 2008 18:55:25 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <9e9bdae7-5e91-4e0c-b783-1ed72311a733@t12g2000prg.googlegroups.com> <2e1de55a-69e5-439e-addc-bde650b4c16a@i36g2000prf.googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls6.std.com 1211583326 21325 192.74.137.71 (23 May 2008 22:55:26 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Fri, 23 May 2008 22:55:26 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:UeayJrsy6lJv8JdR+kS7thGPtmE= Xref: g2news1.google.com comp.lang.ada:306 Date: 2008-05-23T18:55:25-04:00 List-Id: "Randy Brukardt" writes: > "Robert A Duff" wrote in message > news:wccy7633br3.fsf@shell01.TheWorld.com... >> Graham writes: >> >>> In any case, the 5x comparison sounds extreme and probably comes from >>> comparing arrays of ints with something from the Java Collection >>> classes, which is a bit like comparing Ada arrays with Ada Containers. >> >> I don't see why. Ada.Containers.Vectors, for example, does not >> introduce an extra level of indirection for each component of the >> vector. Ada is more like C++ in that regard. > > Sorry, but there is no language guarentee of this; ... Sure. There's no language guarantee of anything related to efficiency. So a programmer has to guess what typical implementations will do. (Or measure.) The semantics of Java require unwanted levels of indirection, unless the compiler goes to heroic/infeasible efforts to eliminate them. The semantics of Ada do not. >...it's more that an > implementation of Ada.Containers.Vectors does not *have* to have a extra > level of indirection. For Janus/Ada, for instance, there would be such an > (implicit) indirection coming from the generic code sharing even if there > isn't any explicit one. Right, it's a trade-off -- code sharing introduces run-time inefficiency for the benefit of compile-time speed. (And smaller code, which might be more efficient in some cases.) > And I'd still expect comparisons to be slower, because the "=" code probably > is a loop doing element comparisons (it has to use the formal "=" operator > and cannot assume that the actual is the predefined "="). It might be > possible for a compiler to optimize that, but it would be pretty complex to > do so. I think that optimization is not too complex on a non-sharing implementation. If "=" happens to be the predefined one, it can be just a bit-wise compare in many cases. >... (And even "=" for integers has to be done in a loop on some > targets -- a bit comparison is not accurate for 1's complement machines, for > instance.) Well, those targets are pretty rare. More important is the fact that floating point minus-zero and plus-zero must compare equal. > The net effect is that generalizations about Ada performance are probably > not well-founded. Usually, Ada performance is similar to that of C++, but > implementation differences can be a big deal and more different than those > between languages. I disagree. Performance of Ada is pretty-close to C and C++ in most cases. Performance of Ada is better than Java (and Smalltalk and ...) in most cases. The implementation matters, but the language rules matter more. - Bob