Different results of java and C verion of same program ?

David Balažic david.balazic@hermes.si
Wed Mar 8 10:06:00 GMT 2006


I wrote:
 
 > Hi!
 >
 > I use gcc 3.3.5 (debian 3.1).
 > *
 > I have written a program in jav*a and compiled it with gcj.
 > Then I ported it to C and compiled with gcc.
 >
 > They give different results !
 >
 > Can this be some compiler error ?
 > Computing accuracy related ?

It turned out, it was a bug in my C code (buffer overflow) :-(

The problem now is : The Java compiled version is "too" slow.

Here are the runtimes :
 - Sun JIT : 800 ms
 - C (optimised build) : 400 ms
 - gcj compiled : 4000 ms

As you see, gcj is 10 times slower. Different -O options don't help.
-O values above 2 make it break (null "pointer" exception right after 
start).

The main part of the program is a double loop, comparing each element of 
a Vector
with all other elements of the Vector (except itself).

Any ideas for speedup ?

I already got about 20% speedup by changing this :

for(int i=0; i<myVector.size() ; i++)
  for(int j=0; j<myVector.size() ; j++)

To this :

int vecSize = myVector.size();

for(int i=0; i<vecSize ; i++)
  for(int j=0; j<vecSize ; j++)

Regards,
David



More information about the Java mailing list