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!news3.google.com!feeder.news-service.com!feeder1.cambrium.nl!feed.tweaknews.nl!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: speed of generic code in Ada (vs Java) References: <9e9bdae7-5e91-4e0c-b783-1ed72311a733@t12g2000prg.googlegroups.com> <2e1de55a-69e5-439e-addc-bde650b4c16a@i36g2000prf.googlegroups.com> <87wsluulj4.fsf@ludovic-brenta.org> <24bf14ef-ff0f-4309-88e0-550cd4a0dd9d@p25g2000pri.googlegroups.com> Date: Sat, 17 May 2008 10:07:48 +0200 Message-ID: <87hccxuze3.fsf@ludovic-brenta.org> User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) Cancel-Lock: sha1:VAgjqmeSC9EzBzBbXGonbCDpbWA= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Organization: Tele2 X-Trace: DXC=O8]0NaWfK=1ELoV1BFSEn36`Y6aWje^Y:`Ue?O]Ogj[=;H=h9 jhc0033@gmail.com writes: > Ludovic Brenta wrote: >> jimmaureenrogers writes: >> > On May 16, 11:31 am, "jhc0...@gmail.com" wrote: >> >> Java only allows 'objects' as generics parameters. So, if you define a >> >> generic class and use 'Integer' as a parameter, your code will be slow >> >> because of the boxing - up to 5x compared to non-generic Int (see the >> >> recent discussion in comp.lang.java.programmer - the 'numerics' >> >> thread). Is the situation similar with generics in Ada, GNAT, >> >> specifically? >> >> > No. >> >> To add to Jim's excellent answer: Ada got it right the first time, >> back in 1980. > > So, if I write a, say, linear equation solver using generics in Ada, > and then instantiate it with single precision, double precision, > complex number single precision and complex number double precision, > you'd expect it to be as fast as the equivalent non-generic versions? Yes, exactly. The language allows that, and also allows the compiler to share the object code for generics (which incurs indirection overhead). In practice, only one compiler shares generics while all others will emit different (and differently optimized) object code for each instance. -- Ludovic Brenta.