Java Linear Algebra Performance
The linear algebra part of ojAlgo is one of its main attractions as well as an essential component to the other parts. Its performance has been continuously monitored during the project's life span. Proposed design changes are always challenged by how they affect performance. This has made ojAlgo one of the best performing Java linear algebra libraries.
JAMA is a linear algebra package for Java developed by The MathWorks and NIST (National Institute of Standards and Technology) in the late 90s with the intension that it would someday be the standard matrix class (I assume) available with the core Java distribution. This did not happen, and JAMA is now an abandoned project. The source code, however, is available and released to the public domain. Its main feature/contribution is that it makes available matrix decomposition algorithms – even Singular Value and Eigenvalue decompositions. The entire JAMA library has been "stolen" and made an integral part of ojAlgo. It is used to compare computation results and performance, or to access features not available in (other parts of) ojAlgo. When JAMA is referenced/mentioned on the ojAlgo web site it is practically always the copy of JAMA that is part of ojAlgo that is meant.
ojAlgo maintains test suites that measure/compare the performance of various linear algebra operations The tests compare ojAlgo to JAMA. The reason these tests exist is to make sure ojAlgo is not unnecessarily slow. (Other tests assert correctness.) If any single operation is (significantly) slower with the "native" parts of ojAlgo than with the JAMA part, it is assumed that there is a fixable problem – and the problem is fixed.
At the moment the (same) tests are executed on an iMac as well as a MacPro. The "raw" execution results are available:
BasicMatrix - matrix multiplication
More than 30 basic linear algebra operations are measured and compared between PrimitiveMatrix and JamaMatrix. The tests are written in terms of the BasicMatrix interface. Perhaps the most interesting operation to test is matrix multiplication. (The BasicMatrix interface differentiates between muliplyLeft and muliplyRight.)
The key difference here is that ojAlgo is multi-threaded and JAMA is not. The iMac has one dual-core CPU, and that makes ojAlgo roughly twice as fast as JAMA. The MacPro has two quad-core CPUs (with hyper threading) - 8 real and 16 virtual cores - and that makes ojAlgo 11 times faster.
JAMA executes a little bit faster on the MacPro than on the iMac (but not even twice as fast).
ojAlgo becomes 7 times faster when moved from the iMac to the MacPro.
MatrixDecomposition - matrix decomposition (division)
This is a performance comparison for Cholesky, LU, QR & SingularValue decompositions between JAMA and ojAlgo's own/native implementations.
The matrices used have 1,000,000 elements. The square matrix is 1,000x1,000, the tall 10,000x100 and the fat 100x10,000. Each calculation is done 100 times in a loop. When solving the right hand side (RHS) is the same as the original matrix (the one that was decomposed).
JAMA's LU and Singular Value decomposition algorithms perform a bit better than ojAlgo's "own" implementations in some, but not all, cases. JAMA is never more than twice as fast as ojAlgo.
ojAlgo is faster than JAMA in many more cases than vice-versa, and is often 10 to 15 times faster. Note that solving an equation system (when the decomposition is already computed) is always faster with ojAlgo.
Now let's see what happens with the same tests on a MacPro...
A surprising thing here is that while ojAlgo executes faster on the MacPro than on the iMac (as expected) JAMA actually performs slower in several tests! This makes ojAlgo faster than JAMA in every single test, and in the most extreme case more than 100 times faster.
The source code for these tests is in CVS. Get the TestProj module, and look in the performance.matrix.* (sub)packages. In no way are any of these tests designed to favour ojAlgo. The reason the tests exist is to help find areas where ojAlgo needs improvement.
Project and site sponsored by Optimatika