Performance tests show Java as fast as C++

Java has endured criticism for its laggard performance (relative to C++) since its birth, but the performance gap is closing

How does the performance of Java applications compare with similar fully optimized C++ programs in theory, benchmarks, and real-world applications?

Most industry analysts make the blanket assumption that Java will always suffer performance disadvantages compared with other languages because Java was developed to allow Java programs to run on multiple platforms. You can find this assumption woven through almost all mainstream articles and opinions regarding Java and NCs in modern enterprises.

Originally

published

in

NC World

So we decided to find out for ourselves just how much of a disadvantage there is between Java and C++, the language to which Java is most often compared. We examined the architectural components of Java and compared the performance of programs written in Java to similar programs in C++.

We expected to see a modicum of lagging performance in Java in each test, though we were skeptical about it running several times slower than C++. To our shock, we rarely found any differences in speed at all. Where Java is significantly slower than C++, it's due to Java's stringent security model or to garbage collection.

While we welcome any performance improvements in any language, it appears that if you can use it in the proper context, Java has already come a long way since its inception -- far enough to be considered a top performer along with C++ in many cases.

The test suite

The analysis divides the execution of a program into four functional groups:

  • Loading Program Executable
  • Running Program Instructions
  • Allocating Memory
  • Accessing System Resources

These are functions that must be performed by any program running on a computer regardless of its implementation language.

Using these functional groups, we can develop a theoretical performance comparison between programs written in C++ and Java. In addition, we tried different coding approaches to demonstrate the performance characteristics for programs in each group.

The tests are divided into three programs:

  1. The Simple Loop Test, which tests performance on function calls, mathematical operations, and up-casting/down-casting

  2. The Memory Allocation Test, which tests memory allocation and release

  3. The Bouncing Globes Test, which measures animation performance and handling of resources

All performance numbers were generated using the following environment:

  • Platform: Windows NT 4.0 service pack 2
  • Hardware configuration: Pentium Pro 200, 128MB RAM
  • Software: Visual C++ 5.0 and Sun JDK 1.1.5

For the purposes of this article, we define a "platform" as a combination of CPU type and operating system. For example, Windows NT running on an Intel processor is one platform, Linux running on Intel processor is another, and Linux running on a Digital Alpha processor is still another platform.

1 2 Page 1
Page 1 of 2