Saturday, February 11, 2012

C++ vs FPC vs Java vs C# benchmarking

There were a lot of microbenchmarks etc. in the net to prove which solution is better -- Java or .NET, yet I decided to write a simple yet useful program (An image processing tool we use in developing games for OpenGL ES devices) and port it to several languages. I've put it into a public repo under

https://github.com/exhu/alimg

My results were so that the fastest solution under Linux was in Java (7 secs), then C++  and FreePascal (11-10 secs average). Yes, C++ slower here, of course you can optimize C++ into unreadable code and get most of the hardware, but the code will be unmaintainable and cryptic, while now it's a balanced solution, and still Java sources are the most user-friendly.

Mono was 4 times slower than Java under Linux (28-30 secs), and .NET was as fast as Java under Windows XP 32-bit under VirtualBox (both do the job for about 17 secs), yet the FreePascal version was even faster than both of them (10 secs -- about the same speed in the VirtualBox as on the real Linux).


Linux:
1) Java (OpenJDK 6)
2) C++, FPC
4) Mono

Windows (under Linux VirtualBox):
1) FPC
2) Java (Oracle Java 6), .NET 4

Assume C++ version would be the fastest under Windows too.

I also need to note that .NET 4 offline installation was rather hard to complete under Windows XP 32-bit SP2, it required several downloads for Windows Installer, Windows Imaging and took 20 minutes to install. Meanwhile Java offline installer (~20 megs) was easy and fast and did not require restarting the OS.


To sum up I would pick FPC for native small to medium applications and Java for cross-platform medium to complex applications. Although Java is surprisingly fast on netbooks it's too memory hungry.

No comments: