Trent said:
Yes, Java is slower then, say, a compiled C++ program. But that is
not comparing apples to apples.
YOU can compile JAVA into an EXE (using JET), and get about the
same results, and actually compare apples to apples.
I don't think this is a particularly useful division of the question.
The things that mainly make Java performance different from C++
performance are mostly outside of the execution model these days. It's
simply fact that a good JIT compiler for Java is generally competitive
with statically compiled native code. The factors to consider in
performance are:
1. Dynamic compiling; this is a factor in favor of Java, in that the JIT
can optimize for a specific set of hardware, whereas static compilers
can at best target a processor family. It's largely for this reason
that floating-point arithmetic in Java can be much faster than the
equivalent code in C++.
2. Garbage collection; while it can theoretically go either way, it
seems that in practice garbage collection in Java is a little slower
(but easier and safer) than manual dynamic memory management in C++.
The margin becomes smaller, though, as improvements are made to
algorithms... and it's very easy to write specific examples where a
garbage-collected heap is far faster.
3. Object model; C++ has the performance advantage in allowing the
programmer to use pseudo-objects explicitly on the stack. These objects
are a bit unorthodox with OO expectations (they don't have identity in
any meaningful sense, for one), but they do allow some programming tasks
to be solved without use of dynamic heap memory, and that can be a
performance win.
4. Threading; while threading is easier in Java than C++, it's also
profusive, in ways that can sometimes cause performance issues. This
makes some Java slower than some C++.
None of those problems are solved with a native compiler, although
advantage #1 for Java can be lost. Native compilers can also do wonders
for memory use and startup penalty. However, the chance at a small
margin of improvement in a static compiler over a JIT is not
particularly significant compared to the remainder of factors in Java's
performance.
--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation