speed of simple loops: comparison to other language

Steve White swhite at aip.de
Wed Jun 30 04:37:52 PDT 2010


Hi,

I have some questions regarding the raw computing speed of the Java VM.  

I've timed some simple numerical (and related) operations written in
various languages, compiled with various compilers, on various platforms. 
They always consist of repeatedly doing some operation to a small array
(small enough that everything fits in an L1 cache) so that the time is
humanly sensible, and then reporting the total time.

Of course, one expects loops in Java to run a bit slower than optimized 
loops in C, as it simply does more: bounds-checking etc.  One surprise is
that in these tests Java's speed is comparable to that of C code optimized
for the platform. 

But there are oddities...  Here's what I see:

  On my Intel x86_64-compatible workstation, C loops compiled with gcc
  complete in time very similar to that of Java loops, running on the
  x86_64 VM supplied by my distro.

  However, on IA-32 machines, using the VM of OpenJDK, the Java loops run
  about half the speed as C loops compiled with gcc.

  I tried building the Java VM from source for my IA-32 machine, but saw no
  improvement in performance at all from the distribution VM.

  My notes from several years ago have IBM Java2-13 doing basic operations
  in very little (apparently a small additive constant) more time than 
  optimized C (using gcc, Linux of the time).  On the other hand, I've 
  observed over the years some VM running the same code a factor of ten
  slower than others.

** Question 1: Why does the "i386" distro VM perform worse relative to C code
than x86_64 VM?

** Question 2: Why would i386 Java VMs perform so much worse than x86_64? 
Is there a way to get better performance on i386-derived platforms?
(special compiler switches, etc?

It would seem that it would be possible to arrange for most obvious
loops in Java to run at speeds very near native speeds.

Find some tests attached.  
The code is unfortunately rather crude.  You'll have to adjust the Makefile

Cheers!

-- 
| -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
| Steve White                                             +49(331)7499-202
| E-Science                                        Zi. 27  Villa Turbulenz 
| -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
| Astrophysikalisches Institut Potsdam (AIP)
| An der Sternwarte 16, D-14482 Potsdam
|
| Vorstand: Prof. Dr. Matthias Steinmetz, Peter A. Stolz
|
| Stiftung privaten Rechts, Stiftungsverzeichnis Brandenburg: III/7-71-026
| -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
-------------- next part --------------
A non-text attachment was scrubbed...
Name: speedtest.tar.gz
Type: application/x-gzip
Size: 10532 bytes
Desc: not available
Url : http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/attachments/20100630/ea5c6a56/attachment-0001.bin 


More information about the hotspot-compiler-dev mailing list