Views
- State: published
Is Java Hundreds of Times Faster than Any Other Language?
|
|
Jack Shirazi's Java performance tuning site has a very strange article showing Java to be hundreds of times faster than any other language. Posted is a benchmark that loops 10,000 billion times, and Java does it under a second! Well, the gotcha is that the loop does nothing:
public class Loop
{
public static void main(String[] args)
{
//10 000 billion iterations
long time = System.currentTimeMillis();
int REPEAT1 = 1000 * 1000;
int REPEAT2 = 1000 * 1000 * 10;
for (int i = 0; i < REPEAT1; i++)
{
for (int j = 0; j < REPEAT2; j++)
{
//do nothing
}
}
time = (System.currentTimeMillis() - time)/1000;
System.out.println("Time taken: (in seconds) " + time);
}
}
I do find it interesting that somehow the JIT compiler was able to optimize out the do nothing loop. Could something similar be happening in Markus Kohler's almost do nothing benchmarks? Well, I'm not going to make the same outrageous claim as the original article, however I can say this: "Java has the most intelligent optimizer than any other language".
[UPDATE] After reading Cedric's post, I'm reminded, I should restate my last statement. I should have said "Java's optimizer is not as dumb as other language compilers or interpreters". Interesting to note though, running "java -client" doesn't optimize out the NOP.
Last modified 2003-07-30 04:14 PM



Try doing something like PrintLine or an arithmetic operation in the for-loop to get some useful results.