• HOME
  • Checking Java and C++ Performance with RE2J
Created time: 2016-04-20 Last updated time:

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.



Suitable language to make NoSQL and Database Engine

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++.

Use regular expression engine RE2J by Google

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.

Java to C++ Converter

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.

Test Codes

I used following code as Test Code.

Java Code

C++ Code

The Java code is converted into following code.

Result of Testing

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).



Go to Top