Re: speed of generic code in Ada (vs Java)



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
.



Relevant Pages

  • Re: Creating IndexOf in a custom collection
    ... I started out with a custom collection by extending ... based on specific properties of the contained class, my Generics based ... Dale Preston ... public int FindIndex ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: .NET generics & the .NET framework: not generic enough?
    ... I do wish there was a way to express that you want int, ... What if I create a BetterInt32? ... Generics are not CLS compatible, however you are free to use generics ... One of the reasons for struct & overloaded operators is to enable us as ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Why cant I overload a generic method based on class/struct?
    ... In the case of generics, defaultwould also return either a null, ... delegate(int lhs, int? ... int position = rhsFirst; ... To call this with char, ...
    (microsoft.public.dotnet.languages.csharp)
  • [PATCH 5/5] remove HAVE_ARCH_CMPXCHG
    ... * indicated by comparing RETURN with OLD. ... static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old, ... cmpxchg(volatile int *p, int old, int new) ...
    (Linux-Kernel)
  • Need faster bitmap compare method
    ... region size im scanning is 128x96 on a 1024x768 bitmap. ... int curx = 0; ... int cury = 0; ... //This code actually does the comparing ...
    (microsoft.public.dotnet.framework.drawing)

Loading