Benchmark
Depending on your CPU and your operating system, one matrix implementation may be faster than another. The following charts give you an overview of the performance of UJMP’s matrix implementations compared to other Java matrix packages on two reference platforms:
- Platform 1: Intel Xeon 2.8GHz, 2 CPUs with two cores each, running under Debian Lenny 32bit, 2GB RAM
- Platform 2: Intel Core2Duo 2.4GHz, 1 CPU with two cores, running under Windows Vista 64bit, 4GB RAM
Both systems are using Sun’s JDK 1.6v12 with 32bit and the results represent average values of several test runs.
We have chosen two tasks which are essential when working with matrices:
- Task 1: Matrix multiplication of two 1000×1000 matrices filled with random double values
- Task 2: Calculating the transpose of a 5000×5000 matrix filled with random double values
To obtain comparable results, we require that a new matrix is returned and that the original data remains unmodified. Some libraries provide more efficient routines which violate these conditions. In this case, we copy the data before the actual operation is executed (time for copying is included in our measurement). To give a comparison to non-Java software, we have tested the same tasks in FreeMat and Octave also.
Here are the results:




As you can see, there is no single best matrix implementation and performance may vary depending on the task. As fas as matrix transposition is concerned, Java software may be superior to Octave or FreeMat.
For two-dimensional dense matrices, we provide two basic implementations:
- DefaultDenseDoubleMatrix2D (UJMP 1): data values are stored in a one dimensional double[] array
- ArrayDenseDoubleMatrix2D (UJMP 2): data values are stored in a two dimensional double[][] array
UJMP gives you the freedom to chose the best implementation for you and you can exchange it if necessary. We also provide interfaces to all Java matrix libraries compared in this benchmark: Jama, Colt, ojAlgo, MTJ, ParallelColt, Shared Scientific Toolbox, Mantissa, commons-math, JSci, JScience. Thus you can chose the fastest library for your platform and use it within UJMP. Other libraries can be integrated very easily.
Here is a comparison of matrix libraries in Java which may help you to chose the best implementation for you.