Java Program Efficiency

Posted by JD 10/05/2008 at 09:51

Java programmers have had a bad rap for years. Your programs are slow and use too much memory has been the cry from compiled binary language programmers.

It is less true today. A good JIT compiler will be within 10% of the speed of C++ for an equally skilled programmer. That doesn’t say that an excellent Java programmer can’t make better code than a poor C++ programmer, they can. It just isn’t as likely for programmers of similar skill in their selected language.

Most of the time, code speed isn’t really that important. 80% of programs are used by less than 10k users, so the performance will be key only where I/O is concerned, not in calculations or GUI code. Calling a function 10k times when you only need to call it once is bad in any language – that’s understood.

In summary, Java programs are less efficient than C++ which is less efficient than C which is less efficient than ASM – provided that all are efficiently written.

Speed will be greater and memory use will be less as you move towards ASM. This is obvious.

OTOH, the speed of development, complexity management and platform flexibility that Java has is probably greater than the other choices and (in your environment) may outweigh the speed and memory differences.

There’s an old programming rule … don’t bother optimizing code that only runs once. Spend 80% of your time optimizing only the code that needs optimization.

Personally, I like cross-platform C++ code as the best of efficiency, memory footprint and code portability when a complex program is being created. But more and more, Ruby, Python, PHP or other scripting languages are faster to create than lovingly crafted C++ or Java and get the job done. That’s what programming is all about – getting the job done.

Trackbacks

Use the following link to trackback from your own site:
https://blog.jdpfu.com/trackbacks?article_id=256