Wednesday, October 12, 2005

Java performance urban legends

From Java theory and practice: Urban performance legends, revisited (I guess this small article got slashdotted a few weeks ago, so everyone probably has already seen it):

Allocation in modern JVMs is far faster than the best performing malloc implementations. The common code path for new Object() in HotSpot 1.4.2 and later is approximately 10 machine instructions, whereas the best performing malloc implementations in C require on average between 60 and 100 instructions per call.

Good to know about that since I always thought anything Java would be slower than C++. Makes me feel less guilty when writing Java.

All this also reminds me of this sig I saw once on usenet:

The march of progress:

C:

printf("%10.2f", x);

C++:

cout << style="font-weight: bold;">

Java:

java.text.NumberFormat formatter = java.text.NumberFormat.getNumberInstance();
formatter.setMinimumFractionDigits(2);
formatter.setMaximumFractionDigits(2);
String s = formatter.format(x);
for (int i = s.length(); i <>

No comments: