News for hackers. Stuff that matters.
Re:In what cases is Java faster than C++? by sfphotoarts on Wednesday February 16, 2011 @01:03PM (#2227446)
This is not true. The runtime environment for Java is capable of changing the program on the fly in response to dynamically determined bottlenecks. To implement such a system in C would be to re-implement Java.

What you cannot do in C/C++ that you can in Java is respond to program inefficiencies at runtime, with runtime knowledge.

Re:In what cases is Java faster than C++? by krakensden on Wednesday February 16, 2011 @01:22PM (#2227532)
That's true, but most programs don't encounter situations where a whole new class of unforeseen optimizations are needed right now, /and/ it's possible to make a significant improvement without changing any algorithms.

For everything else, there is Profile Guided Optimization.

Re:In what cases is Java faster than C++? by stcredzero on Wednesday February 16, 2011 @04:02PM (#2228280)
To implement such a system in C would be to re-implement Java.

Why not use clang compiling to LLVM bytecode and JIT from that?

Re:In what cases is Java faster than C++? by rubashov on Wednesday February 16, 2011 @01:27PM (#2227558)
You are mistaken. There are JIT libraries for C++. There are also dynamic profiling compilers (intel).
Re:In what cases is Java faster than C++? by TheCondor on Wednesday February 16, 2011 @01:45PM (#2227652)
Are you talking about profile guided optimization or a new Intel compiler that produces and application that is capable of dynamically rebuilding its own binary code on the fly? Presumably in the event that it can detect a better way to execute a chunk of code.

There are JIT libraries for C++ for building applications which dynamically compile stuff, I'm not aware of any that dynamically recompile the C++ though.

Re:In what cases is Java faster than C++? by sfphotoarts on Wednesday February 16, 2011 @01:59PM (#2227724)
C++ with a JIT is called Java,

Seriously though this is misguided. PGO is clearly a step in the right direction but its simply deferred static optimization. Either you optimize in C at the compile time, or with PGO by running a few statistically representative executions, but these are not dynamic.

The only way to make truly dynamic optimizations is by having a runtime environment and code that is interpreted.

The argument that its not often necessary is a different argument and with only a few moments thought can be seen to be untrue. Take for example and strstr like operation that you naively implement using by walking through the source string. Now let's say you do this a lot, all is good because the input is short, now you receive (in a parser for example) something much much bigger. A JIT has privy information and can make determinations that building a index on the source string to make repeated finds faster is better, C does not, even with PGO because you may never have run a test that encounters this situation.