comp.lang.ada
 help / color / mirror / Atom feed
From: Graham <graham.stark@virtual-worlds.biz>
Subject: Re: speed of generic code in Ada (vs Java)
Date: Wed, 21 May 2008 01:12:22 -0700 (PDT)
Date: 2008-05-21T01:12:22-07:00	[thread overview]
Message-ID: <c8282ec5-a5cb-4094-b0b1-bad097352250@34g2000hsf.googlegroups.com> (raw)
In-Reply-To: 2e1de55a-69e5-439e-addc-bde650b4c16a@i36g2000prf.googlegroups.com

On May 16, 7:12 pm, "jimmaureenrog...@worldnet.att.net"
<jimmaureenrog...@worldnet.att.net> wrote:
> On May 16, 11:31 am, "jhc0...@gmail.com" <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



  parent reply	other threads:[~2008-05-21  8:12 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-16 17:31 speed of generic code in Ada (vs Java) jhc0033
2008-05-16 18:12 ` jimmaureenrogers
2008-05-16 18:54   ` Ludovic Brenta
2008-05-17  1:50     ` jhc0033
2008-05-17  2:04       ` Georg Bauhaus
2008-05-17  6:32       ` Niklas Holsti
2008-05-17  8:07       ` Ludovic Brenta
2008-05-17 21:37       ` Gautier
2008-05-17 23:31         ` Ivan Levashew
2008-05-22 22:01     ` Florian Weimer
2008-05-21  8:12   ` Graham [this message]
2008-05-21 15:41     ` Robert A Duff
2008-05-22  0:06       ` Randy Brukardt
2008-05-23 22:55         ` Robert A Duff
2008-05-24  0:16           ` Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox