Re: Java slow ?
From: Carl Howells (chowells_at_janrain.com)
Date: 05/28/04
- Next message: John C. Bollinger: "Re: Garbage Collection"
- Previous message: Mark Thornton: "Re: Java slow ?"
- In reply to: David Eng: "Re: Java slow ?"
- Next in thread: Roedy Green: "Re: Java slow ?"
- Reply: Roedy Green: "Re: Java slow ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 27 May 2004 15:03:30 -0700
David Eng wrote:
>
> Java and C++ can create objects in the heap. If you compare this
> feature between Java and C++, no doubt that the speed is about the
> same.
Completely wrong. Allocating objects on the heap in Java is FAST.
(It's the initialization of the object that takes time, not the
allocation.) The new operator in C++ has to do MUCH more work to
allocate an object than the new operator in Java, because of the way
modern garbage collection algorithms lay out the heap.
> The second example is array. If Java and C++ allocate an array using
> index, the speed should be the same. However, C++ allows you using
> pointer arithmetic. Instead of locating an element of array you must
> start from the begin of the array every time, pointer arithmetic can
> locate the element based on previous position. When the elements of
> the array increase, the speed of allocating an array using index will
> much slower that pointer arithmetic.
Well, at least this isn't completely wrong. It's just mostly wrong.
It's actually fairly trivial for a compiler to optimize indexed array
lookups in a loop to pointer increments in that loop. I'm not actually
certain that this is done in any JVM, (it wasn't a few years ago), but
it certainly will be in the future.
Remember: In terms of optimization, lack of flexibility is a good
thing. When the language just doesn't let you screw up code the way C
and C++ do, the compiler can safely employ optimizations that just
aren't possible in C or C++.
Take a good compilers course sometime. You'll learn quite a bit.
- Next message: John C. Bollinger: "Re: Garbage Collection"
- Previous message: Mark Thornton: "Re: Java slow ?"
- In reply to: David Eng: "Re: Java slow ?"
- Next in thread: Roedy Green: "Re: Java slow ?"
- Reply: Roedy Green: "Re: Java slow ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|