TM Research Journal

Tuesday, April 04, 2006

DSTM: Java Vs. C

Ok. Today I managed to implement the same test in Java as the one I had in C (increment and decrement a shared counter equally).

First of all, I've never written a Java program before. It was easy enough for me to follow Java programs that have already been written, but writing my own proved to be more difficult. To be honest, I do not like the Java language. But eventually I got it done.

Anyway, as for the results. For 2 million increments and the same decrements, here's how three different platforms performed (all running the Polite Contetion Manager):-

Sun CC (without -fast)
Time 0:16
RSS 1864

Sun CC (with -fast compiler option)
Time 0:12
RSS 1856

Java (default compilation)
Time 0:14
RSS 17960

What this tells us is that appearantly, the Java version performs better than the default C compilation - this is most probably due to Java having better garbage collection than C (since the C garbage collector has to be conservative). It could also be due to my own code, but I followed the Java program in porting as closely as possible so I don't think that's the issue.

I don't know if it's fair to compare the optimized C port with the Java one, since I am not familiar with any optimizations for the Java compiler. I need to ask about this.

Finally, the Java version obviously consumes a lot more memory due to the loading of the JVM.

In conclusion, it seems that the C port is comparable to the Java port in terms of performance, but more tests need to be done.

0 Comments:

Post a Comment

<< Home