On 29/07/2010 6:19 PM, Kirk wrote:
Sorry, I just don't buy the standard line that C/C++ is a safe from a
performance perspective. Array access in Java will be every bit as fast. Range
checking will most likely be jit'ed out of the code. Direct access will most
likely be jit'ed into the code....
Regards,
Kirk
I can only base it on one personal mid-sized program that I have done
myself (involving lots of XML parsing in Java and C++) which went around
10 times faster in C++ (a year or two back), and articles I can find
doing Google searches. Anyone who has concrete info would be great.
But it really needs the same program implemented in Java and C++ to do
direct comparisons. Some of the articles have so much subjective
sounding text in them I simply do not believe them. (One more
realisitic one involved was I think Quake being ported to Java and
performing just as well - but I don't know if most of the time is really
spent in the GPU rather than Java itself.)
Based on personal experience (10+ years of C++ programming and 5+ years
of Java programming), the discussions I have had writing performant C++
code involve talking about memory alignment, cache lines, avoiding
memory copies, templating, inlining, looking at the resultant assembler
etc. You can write multiple classes in C++, then use them to build up a
more complex data structure where the whole structure takes a single
malloc to create. Java if you use multiple classes you get multiple
memory allocations (one per object instance). In C++ I can write an
array of classes (or structs) and all the objects are inlined in the
array - in Java I have to have an array of references to objects, with a
new object for each value in the array. In writing Java you don't have
the sort of control as in C++. However in Java memory management is
cheaper (if you have the same number of mallocs!). In one large
(multi-million line C++ code) multi-threaded program, we found changing
the memory allocation library had a 20% difference (or more) in overall
performance. No other change the C++ code - just link in a different
malloc library and major difference in performance. We have had to
worry about things like which threads data structures were allocated
from as the malloc library had a pool per thread. If a different thread
ends up doing the frees, you end up with lots more lock contention in
the malloc library.
I don't want to get carried away here (its all been said before and I
did not mean to start Yet Another Language War), but I have read on the
web numerous opinions (not much evidence) saying Java can generate code
around the same performance as C++ code. I have never seen anything I
trust saying it can be much faster. I have heard (and experienced)
cases where its definitely much slower. I have heard many people I
trust in different forums all say C++ code executes faster - use it when
you want to control performance. Its backed up by personal experience.
I have not heard of significant sized projects where Java saved the day
over C++ in terms of performance (that are backed by believable
evidence). What I do believe is Java is much more productive for
programmers, pretty good in performance, and does have harder to measure
benefits in the more modern garbage collectors that only come up when
you have a large running system. Talk to our sysadm admins about Java
and they want to know if anything else needs to run on the same box as
if you have a few Java processes memory consumption goes through the
roof (compared to equivalent C/C++ programs) - making it harder to share
a box without problems. Not trying to be argumentative here, but I have
not seen any evidence that can change my mental model of Java = easier
to write and maintain, C++ = higher performance. (I guess I should add
C# = Microsoft.)
Final word in micro benchmarks, I know their limitiations (have done
lots of performance analysis over the years), but in the words of
Charles Babbage http://en.wikipedia.org/wiki/Charles_Babbage "Errors
using inadequate data are much less than those using no data at all".
Thanks all!
Alan
--
You received this message because you are subscribed to the Google Groups "The Java
Posse" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/javaposse?hl=en.