DesignPerformance
From JQuantLib
Problem
Performance of numerical Java applications can be poor.
Solution
First of all, performance is a subject that becomes impossible to debate if we consider till the last millisecond. It's even more confused if you take the exact same code (or almost the exact same code!) written in Java and C++ and run on different hardware platforms: results can be totally different on different platforms. I prefer to adopt a certain "threshold" of I'd say, 30% which means that a difference of 30% or less means we dont have precision enough to compare and both should be considered similar.
Taking the previous paragraph into consideration, Java code can be compared with equivalent C++ code:
- 32bit integer arithmetic: as fast as;
- 64bit double arithmetic: as fast as;
- sort algorithms: 50% slower;
- list operations: 2x slower;
- matrix operations: 2x to 3x slower;
- nested loops: 2x slower;
- trigonometric functions: poor!
In order to address the major issues, we evaluated these technologies:
- FastUtil package which offers Colletions of primitive types. This is where Java code can beat C++ code due to the way C++ handles pointers as opposed to the way Java handles arrays.
- JAL package which mimics most of C++ STL functionality, providing fast algorithms on arrays of primitive types, which perform much faster than arrays of Objects.
- Colt package which is an excellent class library used by CERN. In particular Colt has modified versions of JAL and FastUtil in it.
- Parallel Colt package is a re-implementation of Colt package and aims to take advantage of modern multi-core CPUs.
We have chosen Colt because:
- Colt is a well implemented, fast and stable mathematical, linear algebra library;
- Colt has JAL somewhat 'integrated';
- Colt can be 'upgraded' more or less easily to Parallel Colt;
Other options:
- FastUtil can be used in places where functionalities from Java Collections Framework are really important.
See also:
- Java performance at Wikipedia has an overview of the subject and some overall results.
- Microbenchmarking C++, C#, and Java at DDJ has a general test suite and serious evaluation of results.
- Fixed, Floating, and Exact Computation with Java's BigDecimal presents situations when BigDecimal could be used instead of double.
- Java Performance has a good starting point on several subjects related to Java performance.
- Mustang's HotSpot Client gets 58% faster! suggests that Java performance is getting better and better.
- How Java's Floating-Point Hurts Everyone Everywhere is an excellent discussion about accuracy of floating point operations in Java
- Java and Numerical Computing An overview on the major difficulties for numerical computing with Java including a list of do's and dont's
RichardGomes 14:24, 10 February 2008 (UTC)

