I am writing a block-based game. I began in Java using JOGL, having had recent experience with that pair on another project. Later, in defference to the many conversations about JOGL vs LWJGL, I ported to that library and posted the experienc here (performance was identical, but LWJGL easier to use).
Well, in speaking with some friends I learned that it's not as hard to write portable C++ code as I thought, particularly with C++ 11 (I was terrified of having to mess with XCode to get a Mac port working!). So, given that C++ is my favorite language, I ported my game again.
Why I think this matters
There are often threads here (and elsewhere) asking about what language a person should learn, or asking if certain language/platform choices are good ones to make games on. My view where most OpenGL-based games are concerned is that the performance bottlenecks are almost always GPU based, and as modern GL use uploads all data to the GPU, the language will rarely matter. Consider Minecraft: could this game be "better" or faster if it had been written in C++? Sure, the code could run faster (if written well), but the frame rate would not necessarily improve. To say it another way, Minecraft could be improved through optimization within its current language (Java) more than by a move to another language.
So why would I rather work in C++?
I know it best. I have many more years of experience in C++, and having also many years of assembler, am able to write much more performant code. For the vast majority of uses, this would not matter, but being a bit of an optimization fanatic, I like to keep resource use low "just in case." This is impractical, but part of my character as a programmer.
So what were my results after porting?
My Java code was written "just to make it work," i.e., no optimization whatsoever. The C++ code was as trivial a port as could be done, also with no optimization.
Note: I spent a fair amount of time optimizing use of the GPU, and that work is language agnostic, but really no work optimizing for the CPU.
The program renders as many as four million block faces, meshed into perhaps two million triangles (one million quads). It uses frustum culling, z-test and a few tricks to eliminate geometry that does not need to be rendered, but nothing else.
My results were as follows:
* No change in framerate (~265 fps, minimum, in both languages, and > 3,000 maximum)
* No change in CPU use while playing (~10%, but it is as yet single threaded on a 6-core box)
* Perhaps 15% faster world generation time in C++
* Slightly smaller memory use in C++ as apposed to Java
Although the numbers differ, the difference (no difference) is similar across many different PCs and GPUs.
From personal experience, I know that*
* I can bring the CPU use down for C++, and also bring down the world-gen time (with a little optimization)
* I can bring the memory use down dramatically in C++
But one more part of the experience bears some mention: development and debugging.
In Java, all builds are created equal. They all run with full debug support, and they run fairly fast.
In C++, release builds are the fastest but lack even trivial debug support. Debug builds are unbelievably slow.
Also, a Java port to another platform requires a few command line switch changes, whereas a port in C++ requires a platform-specific build which, while easier than I had thought (using glfw, etc.), is still much more technically challenging than with Java.
For an experienced C++ programmer, and particularly working on a long-term project, in which future requirements may demand the utmost performance, and for which the time to do platform-specific builds is comparitively small, C++ is what I will choose to use.
However, if tasked with building anything with more certain requirements, or in which the CPU-related needs are both known and moderate (at least not high), Java is a better language, at least insofar as I know I can complete the work and cross-platform port in far less time.
To put it another way: assuming Notch is reasonably skilled, Minecraft would not be better nor give higher FPS if written in C++. Therefore, for most games, people should choose the language they are most productive in.
A few details, for those that care
The data in this post does not depend on tech specs, but I know I often want them when I read such things, so here they are.
I am running Windows 8.1 on an i7 980x (6-core) CPU with 24 GB 1,600 tripple channel DDR-3. It has a Radeon HD 5870 GPU. I am developing with Microsoft Visual Studio 2013 Express (for C++) and Intelli-J Community edition (for Java).