Indeed, there is no easy way around this and many (most?) numerically
intensive programs use small vectors and matrices.
So the conclusion can only be that Java is not suitable for such
applications.
Omitting the rest of the discussion, I would like to reply to that
last statement only.
First. The languages are roughly divided into "compilative" and
"interpretative". For the first ones more checks and optimizing work
can be done at compile-time, while for the later they all fall to
run-time. Interpretation loops of VM, start ups etc. take their time
for work non-productive from the end-result point of view.
Java, from one side, is implemented as a compilative language, i.e.
with a JVM interpreter. You pay this price for being
platform-independent.
From another side, Java, in most of its features is a well-compilable
language, alike C and C++.
The solution that I have proposed giving my statistics, was to compile
your application for a known target platform (if it is x86/Windows, it
can be JET (
http://www.excelsior-usa.com/jet.html), or it can be
GCJ... The reason was to get rid of the interpreting engine - JVM and
to benefit of the powerful optimizing techniques implemented in modern
compilers.
Second. A theorem: For any language, any platform and any hardware
there exists a problem that cannot be efficiently solved with them.
Proof: consider any polynomic or NP-complete problem with high
factors.
Usually, is is not a tool to be blamed. Special methods to solve these
"hard tasks" should be elaborated, standard algorythms should be
optimized into special versions, etc.
Consider the case that is now fundamental to programming with Windows:
I mean "invalidation rectangles". I bet that initially the problem was
that redrawing the full heap of windows on a screen when something
changes in one of them was not acceptible (redrawing time being much
more the eye wink time). Suppose that with modern speeds it is
possible to recalculate the full screen picture at a time less than a
screen update frequency (60Hz). Who would ever think on that problem?
Hence the statement: a program that will need to be optimized should
be optimized not only at the latest phase, when a VM or a compiler try
to do their best, and not even (though in more extent) at the phase of
coding the algorythm on a particular language, but yet on the phase of
algorythm selection.
As for the language, the skills of writing fast-working programs may
be somewhat different from the skills of writing programs "as books
and professors teach". It may be more preferrable to unroll loops, to
precalculate often used data into huge static arrays, write in a mix
of languages (well, after all, if 90% of time your program spents in a
5-lines loop, isn't it a reason to write this loop in assembler than
to reject the language which is perfect for rest N-5 lines??), etc.
etc...
So, the art of optimizing programs is an art indeed that should be
learnt as we learn to program
Vit
Excelsior, LLC