A single benchmark doesn’t prove anything, so why not add another well known benchmark. I took NBody (as I always did on this blog ;-)).
The results for NBody confirmed those results. For C I took the fastest plain C implementation from the Computer Language Benchmarks Game. Once again the y-axis shows the duration (this time in seconds).
- Slower and faster usually cause headaches in benchmarks (There a nice paper about that http://hal.inria.fr/docs/00/73/92/37/PDF/percentfaster-techreport.pdf). I sticked with the elapsed time, such that e.g. 42% slower means that the factor of the durations was 1.42.
- On the MacBook Pro C was compiled with clang using -O3 -fomit-frame-pointer -march=native -mfpmath=sse -msse3 for x64. Java was Oracle Hotspot 1.8.0-ea-b87 on 64 bit (thus C2 aka Server Hotspot). Chrome was 28.0.1493.0, but the 32 bit version. I tried to compile V8 myself, but both the x86 and x64 custom built V8 were significantly slower than Chrome so I stick with Chrome.
- On the iPhone I used a release configuration using clang with (among others) -O3 -arch armv7
- The Google Nexus 7 runs Android 4.2.2, Chrome 26.0.1410.58. C was compiled with -march=armv6 -marm -mfloat-abi=softfp -mfpu=vfp -O3.
>>Java is 206% slower than Java<>no SSE intrinsics<<
But -mfpmath=sse -msse3 ?
Thanks for spotting hat typo. Enabling SSE is fine (Java and V8 use it on the desktop too).
Could you show us the C and Java versions of the source? How did you calculate the elapsed time (e.g. does the Java version include JVM startup time?).
You can download the source code here.
Yes, startup time is fully included for both V8 and Java. The reason for this is that a user won’t care if the code is AOT compiled or with a profiling JIT, so they better be fast enough the first run or “native” languages will win (especially for mobile devices).
DALVIK != JAVA
Dalvik might not be an official (which means Oracle) or certified Java TM virtual machine (this is why I even put “Java” in quotation marks when I talked about the Dalvik VM), but for sure the code it runs was written in the Java programming language. And it even is THE way to run Java code on Android.