Fork me on GitHub
Menu
Home

What's in it?

Linear Algebra
Mathematical Programming
Modern Portfolio Theory

License
Download
Documentation
Support & Services
 
BLaadin Edge

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.)

 
multiplyLeft() + multiplyRight()
1000x1000
     
 
JAMA
ojAlgo
Gain
iMac
3843s
1871s
x2
MacPro
2962s
264s
x11
Gain
≈1
x7
 
 
ojAlgo v28.22 2009-10-25&26
iMac:, 2.4 GHz Intel Core 2 Duo, 3 GB 667 MHz DDR2 SDRAM
MacPro: 2 x 2.26 GHz Quad-Core Intel Xeon, 6 GB 1066 MHz DDR3
OS X 10.6.1, JVM 1.6 64-bit

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.

JAMA   ojAlgo
<=>
<=>
<=>
<=>
 

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).

ojAlgo v28.22 2009-10-25
iMac, 2.4 GHz Intel Core 2 Duo, 3 GB 667 MHz DDR2 SDRAM
OS X 10.6.1 (32-bit kernel), JVM 1.6 64-bit
compute() solve() compute() + solve()
1000x1000
JAMA ojAlgo Gain JAMA ojAlgo Gain JAMA ojAlgo Gain
Cholesky
27s
19s
≈1
1379s
132s
x10
1406s
150s
x9
LU
55s
79s
≈1
280s
131s
x2
334s
210s
x2
QR
703s
90s
x8
1890s
213s
x9
2594s
303s
x9
SingularValue
5439s
7531s
≈1
227s
145s
x2
5666s
7677s
≈1
Eigenvalue
2034s
   
193s
   
2227s
   
 
compute() solve() compute() + solve()
10000x100
JAMA ojAlgo Gain JAMA ojAlgo Gain JAMA ojAlgo Gain
Cholesky
                 
LU
22s
15s
≈1
           
QR
121s
18s
x7
656s
41s
x16
777s
59s
x13
SingularValue
635s
37s
x17
25s
14s
x2
660s
51s
x13
Eigenvalue
                 
 
compute() solve() compute() + solve()
100x10000
JAMA ojAlgo Gain JAMA ojAlgo Gain JAMA ojAlgo Gain
Cholesky
                 
LU
11s
22s
/2
           
QR
49s
24s
x2
           
SingularValue
634s
62s
x10
           
Eigenvalue
                 
 

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...

ojAlgo v28.22 2009-10-26
MacPro, 2 x 2.26 GHz Quad-Core Intel Xeon, 6 GB 1066 MHz DDR3
OS X 10.6.1 (64-bit kernel), JVM 1.6 64-bit
compute() solve() compute() + solve()
1000x1000
JAMA ojAlgo Gain JAMA ojAlgo Gain JAMA ojAlgo Gain
Cholesky
23s
17s
≈1
2161s
20s
x107
2184s
37s
x58
LU
44s
21s
x2
142s
20s
x7
188s
41s
x5
QR
1132s
24s
x46
3130s
42s
x74
4263s
67s
x64
SingularValue
7585s
7178s
≈1
154s
20s
x8
7739s
7199s
≈1
Eigenvalue
2889s
   
153s
   
3043s
   
 
compute() solve() compute() + solve()
10000x100
JAMA ojAlgo Gain JAMA ojAlgo Gain JAMA ojAlgo Gain
Cholesky
                 
LU
10s
5s
x2
           
QR
86s
6s
x14
257s
7s
x37
343s
13s
x26
SingularValue
402s
13s
x31
17s
10s
x2
420s
23s
x18
Eigenvalue
                 
 
compute() solve() compute() + solve()
100x10000
JAMA ojAlgo Gain JAMA ojAlgo Gain JAMA ojAlgo Gain
Cholesky
                 
LU
8s
4s
x2
           
QR
33s
5s
x7
           
SingularValue
404s
20s
x21
           
Eigenvalue
                 
 

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.


SourceForge.net LogoProject and site sponsored by Optimatika
Copyright © 2000 - 2014

Google+

Using JProfiler from ej-technologies