Checking Java and C++ Performance with RE2J
I'm now making nosql and relational hybrid database engine. It has Java version and C++ version. Therefore we can compare these performance.
Recently there are a lot of Nosql and Database engines written in Java, C, C++, and Other languages.
There are many NoSQL engines those are written in Java language and using JVM. And most of traditional database engines are written in C or C++.
Therefore I focused on Java and C++.
When thinking about performance of programming language, I'm focus on program which do not use I/O. That is because the CPU and Memory usage is the big difference between Java and C++.
Handling File and Network I/O is slow and it depends on hardware, so it has almost nothing to do with performance of executing programming code.
There are huge instructions for memory. That makes big difference even if each instruction is very fast.
I've made a compiler that concerts Java source code into C++ code. It uses own garbage collection engine written in C++.
By using this engine, the C++ code and Java code do same operation.
I used following code as Test Code.
The Java code is converted into following code.
C++ is about 200 times faster than Java. I think that is because the native code generated by C++ compiler, this time gcc, uses CPU cache effectively.
C++ program can execute the code in 100 micro seconds.
But the Java spent more that 20,000 micro seconds (20 milli seconds).