<p>I was discussing neural networks (NN) with a friend over lunch the other day and he claimed the the performance of a NN written in Java would be similar to one written in C++.  I know that with 'just in time' compiler techniques Java can do very well, but somehow I just don't buy it.  Does anyone have any experience that would shed light on this issue?  <a href="http://en.wikipedia.org/wiki/Comparison_of_Java_and_C%2B%2B#Performance" rel="nofollow noreferrer">This page</a> is the extent of my reading on the subject.</p>

[{'answer_id': 64622, 'author': 'Jason Cohen', 'author_id': 4926, 'author_profile': 'https://Stackoverflow.com/users/4926', 'pm_score': 5, 'selected': True, 'text': '<p>The Hotspot JIT can now produce code <em>faster</em> than C++.  The reason is run-time empirical optimization.</p>\n\n<p>For example, it can see that a certain loop takes the "false" branch 99% of the time and reorder the machine code instructions accordingly.</p>\n\n<p>There\'s lots of articles about this.  If you want all the details, read <a href="http://java.sun.com/performance/reference/whitepapers/6_performance.html" rel="noreferrer">Sun\'s excellent whitepaper</a>.  For more informal info, <a href="http://www.javaworld.com/jw-03-1998/jw-03-hotspot.html" rel="noreferrer">try this one</a>.</p>\n'}, {'answer_id': 64714, 'author': 'Kevin', 'author_id': 6386, 'author_profile': 'https://Stackoverflow.com/users/6386', 'pm_score': 2, 'selected': False, 'text': "<p>I'd be interested in a comparison between Hotspot JIT and profile-guided optimization optimized C++.</p>\n\n<p>The problem I see with the Hotspot JIT (and any runtime-profile-optimized JIT compiler) is that statistics must be kept and code modified.  While there are isolated cases this will result in faster-running code, I doubt that profile-optimized JIT compilers will run faster than well optimized C or C++ code in most circumstances.  (Of course I could be wrong.)</p>\n\n<p>Anyway, usually you're going to be at the mercy of the  larger project, using the same language it is written in.  Or you'll be at the mercy of the knowledge base of your co-workers.  Or you'll be at the mercy of the platform you are targetting (is a JVM available on the architecture you're targetting?).  In the rare case you have complete freedom and you're familiar with both languages, do some comparisons with the tools you have at your disposal.  That is really the only way to determine what's best.</p>\n"}, {'answer_id': 64734, 'author': 'jrudolph', 'author_id': 7647, 'author_profile': 'https://Stackoverflow.com/users/7647', 'pm_score': 0, 'selected': False, 'text': '<p>This is not strictly about C++ vs Java performance but nonetheless interesting in that regard: A <a href="http://lambda-the-ultimate.org/node/2552" rel="nofollow noreferrer">paper</a> about the performance of programs running in a garbage collected environment.</p>\n'}, {'answer_id': 64791, 'author': 'Nemanja Trifunovic', 'author_id': 8899, 'author_profile': 'https://Stackoverflow.com/users/8899', 'pm_score': 2, 'selected': False, 'text': '<p>The only possible answer is: make a prototype and measure for yourself. If my experience is of any interest, Java and C# were always much slower than C++ for the kind of work I was doing - I believe mostly because of the high memory consumption. Of course, you can come to a completely different conclusion.</p>\n'}, {'answer_id': 65952, 'author': 'Alan Krueger', 'author_id': 7708, 'author_profile': 'https://Stackoverflow.com/users/7708', 'pm_score': 0, 'selected': False, 'text': '<p>If excessive garbage collection is a concern, you can always reuse unused high-churn objects.</p>\n\n<p>Create a factory that keeps a queue of SoftReferences to recycled objects, using those before creating new objects.  Then in code that uses these objects, explicitly return these objects to the factory for recycling.</p>\n'}, {'answer_id': 1149400, 'author': 'clemahieu', 'author_id': 45938, 'author_profile': 'https://Stackoverflow.com/users/45938', 'pm_score': -1, 'selected': False, 'text': "<p>In the grand scheme of things, you're debating maybe a 5% performance difference where you'd get several orders of magnitude increase by moving to CUDA or dedicated hardware.</p>\n"}, {'answer_id': 6347791, 'author': 'Jarek Przygódzki', 'author_id': 293933, 'author_profile': 'https://Stackoverflow.com/users/293933', 'pm_score': 0, 'selected': False, 'text': "<p>Probably C++, although I believe you'll hardly notice the difference besides a slow startup time. Java however makes development faster and maintenance easier.</p>\n"}]
['https://Stackoverflow.com/questions/64582', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/7545/']