Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007
This article does a comparison of Java versus C/C++ performance on numerical code. Those who tend to think of Java as a slower language with significantly higher overhead than something like C may be surprised by the results of the various benchmarks which show Java doing better than C/C++ in many cases. After going over the results, the article then goes on to suggest that Java may soon be faster than C/C++. It gives a number of explanations why, which in some combination may also explain why Java did better than C/C++ in some benchmarks.
Anyone who has programmed anything significant in C or C++ knows the difficulty of keeping track of pointers and managing memory correctly and efficiently. While this may create quite a headache at times, the bigger problem with pointers in C/C++, a problem which most likely affects performance more, has to do with compiler optimization. Many times the C/C++ compiler can't determine where a pointer will be pointing to, and as a result, more variable values have to be written/read from memory instead of registers (which would be much faster).
As noted by Russell Myers in his discussion, Java's garbage collection may come off as either an irritation or an awesome feature depending on who you ask. In response to/reflection on the part of Amro Mousa's discussion concerning memory management/garbage collection, while Java's garbage collection does have it's obvious disadvantages, many people never acknowledge the benefits aside from the fact that it makes memory management easier - which in many people's eyes doesn't justify the supposed overhead. In C/C++, allocating memory requires searching for an empty space in memory of the correct size, or possibly even more work if a reasonable sized chunk isn't found. As a result, the place found by malloc may be fairly random. Java's memory allocator doesn't need to do this same type of search since it already knows where the available memory is and can return it right away. In addition, the memory location returned is adjacent to memory recently allocated (which was most likely recently used). Because of this memory locality and how caches typically work, the newly allocated memory is more likely to be in the cache, making accesses to it much faster than if it wasn't.
By taking care of memory allocation/deallocation automatically, keeping memory locality, and using run-time/JIT optimizations that a pre-compiler can't, Java is able to take some of the focus off optimization of code so the programmer can better focus on what their code does instead of how it's doing it. On the other hand, C/C++ does offer more control over some things, as well as a lower level of control by default; making it easier/better in some situations.
Links to this Page
- Fall 2005 Who's Who last edited on 9 June 2011 at 5:25 pm by cc-vpn-tso249.cc.gatech.edu
- Team Fouse last edited on 9 November 2005 at 11:11 pm by chiapas-win.cc.gatech.edu