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 Path: g2news1.google.com!news1.google.com!postnews.google.com!34g2000hsf.googlegroups.com!not-for-mail From: Graham Newsgroups: comp.lang.ada Subject: Re: speed of generic code in Ada (vs Java) Date: Wed, 21 May 2008 01:12:22 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <9e9bdae7-5e91-4e0c-b783-1ed72311a733@t12g2000prg.googlegroups.com> <2e1de55a-69e5-439e-addc-bde650b4c16a@i36g2000prf.googlegroups.com> NNTP-Posting-Host: 81.151.76.110 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1211357543 627 127.0.0.1 (21 May 2008 08:12:23 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 21 May 2008 08:12:23 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: 34g2000hsf.googlegroups.com; posting-host=81.151.76.110; posting-account=04rmagoAAABZ9PN7u3MdbKIs6DPG57E- User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9) Gecko/2008051202 Firefox/3.0,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:276 Date: 2008-05-21T01:12:22-07:00 List-Id: On May 16, 7:12=A0pm, "jimmaureenrog...@worldnet.att.net" wrote: > 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. > > Jim Rogers On the Java side, generics make no difference to run times, indeed (as I remember) no difference to the generated code at all. It's the autoboxing that slows things down - java has both an int as a primitve type (like an Integer in Ada) and an Integer class, which contains formatting methods and the like but which can't be used directly in an equation. Only the Integer class can be used in Generics Java 1.5 and above compilers allow you to use Integers where you really mean ints - that's the autoboxing. It's generally held to be A Bad Thing. 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. Alternatively, if you defined an Integer_Class in Ada with operators that allowed it to be used in assigments, I imagine you'd see similar performance hits to Java's autoboxing. Just for balance... Graham