Re: speed of generic code in Ada (vs Java)
- From: Graham <graham.stark@xxxxxxxxxxxxxxxxxx>
- Date: Wed, 21 May 2008 01:12:22 -0700 (PDT)
On May 16, 7:12 pm, "jimmaureenrog...@xxxxxxxxxxxxxxxx"
<jimmaureenrog...@xxxxxxxxxxxxxxxx> wrote:
On May 16, 11:31 am, "jhc0...@xxxxxxxxx" <jhc0...@xxxxxxxxx> 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
.
- References:
- speed of generic code in Ada (vs Java)
- From: jhc0033@xxxxxxxxx
- Re: speed of generic code in Ada (vs Java)
- From: jimmaureenrogers@xxxxxxxxxxxxxxxx
- speed of generic code in Ada (vs Java)
- Prev by Date: Re: Prototyping with Ada
- Next by Date: Re: Prototyping with Ada
- Previous by thread: Re: speed of generic code in Ada (vs Java)
- Next by thread: Re: speed of generic code in Ada (vs Java)
- Index(es):
Relevant Pages
|
Loading