Class BenchmarkMatrix2D
- java.lang.Object
-
- cern.colt.matrix.impl.BenchmarkMatrix2D
-
class BenchmarkMatrix2D extends java.lang.ObjectBenchmarks the performance of matrices. Here are the results of some encouraging measurements. Note that all benchmarks only measure the time spent in accessing a matrix element; they exclude the loop itself.Iteration Performance [million method calls per second]
Pentium Pro 200 Mhz, SunJDK 1.2.2, NT, java -classic,
60 times repeating the same iterationElement typeMatrix2D type .DenseDoubleMatrix2D
1000 x 1000SparseDoubleMatrix2D
100 x 1000,
minLoadFactor=0.2, maxLoadFactor=0.5, initialCapacity = 0getQuick setQuick getQuick setQuick double 5 5 1 0.27 int 5 5.5 1 0.3 As can be seen, sparse matrices are certainly not quite as quick as dense ones, but not really slow either. Considering their minimal footprint they can be a real alternative.
Comparing the OO abstractions to zero-abstraction primitive Java arrays may or may not be useful. Still, the table below provides some interesting information. For example, access to Type_T_Matrix2D is quicker than naive usage of Type_T_[]. Primitive arrays should only be considered if the optimized form can be applied. Note again that all benchmarks only measure the time spent in accessing a matrix element; they exclude the loop itself.
Iteration Performance [million element accesses per second]
Pentium Pro 200 Mhz, SunJDK 1.2.2, NT, java -classic,
200 times repeating the same iterationElement typeMatrix2D type = Java array double[][].Unoptimized Form
1000 x 1000
for (int row=0; row < rows; row++) { for (int col=0; col < columns; ) { value = m[row][col++]; ... } }Optimized Form
1000 x 1000for (int row=0; row < rows; row++) { int[] r = matrix[row]; for (int col=0; col < columns; ) { value = r[col++]; ... } }getting setting getting setting double 1.6 1.8 18 11 int 1.5 1.8 28 26 - Version:
- 1.0, 09/24/99
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedBenchmarkMatrix2D()Makes this class non instantiable, but still let's others inherit from it.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voiddoubleBenchmark(int runs, int rows, int columns, java.lang.String kind, boolean print, int initialCapacity, double minLoadFactor, double maxLoadFactor)Runs a bench on matrices holding double elements.static voiddoubleBenchmarkMult(int runs, int rows, int columns, java.lang.String kind, boolean print, int initialCapacity, double minLoadFactor, double maxLoadFactor)Runs a bench on matrices holding double elements.static voiddoubleBenchmarkPrimitive(int runs, int rows, int columns, boolean print)Runs a bench on matrices holding double elements.static voiddoubleBenchmarkPrimitiveOptimized(int runs, int rows, int columns, boolean print)Runs a bench on matrices holding double elements.static voidintBenchmark(int runs, int rows, int columns, java.lang.String kind, boolean print, int initialCapacity, double minLoadFactor, double maxLoadFactor)Runs a bench on matrices holding int elements.static voidintBenchmarkPrimitive(int runs, int rows, int columns, boolean print)Runs a bench on matrices holding int elements.static voidintBenchmarkPrimitiveOptimized(int runs, int rows, int columns, boolean print)Runs a bench on matrices holding int elements.static voidmain(java.lang.String[] args)Benchmarks various methods of this class.
-
-
-
Method Detail
-
doubleBenchmark
public static void doubleBenchmark(int runs, int rows, int columns, java.lang.String kind, boolean print, int initialCapacity, double minLoadFactor, double maxLoadFactor)Runs a bench on matrices holding double elements.
-
doubleBenchmarkMult
public static void doubleBenchmarkMult(int runs, int rows, int columns, java.lang.String kind, boolean print, int initialCapacity, double minLoadFactor, double maxLoadFactor)Runs a bench on matrices holding double elements.
-
doubleBenchmarkPrimitive
public static void doubleBenchmarkPrimitive(int runs, int rows, int columns, boolean print)Runs a bench on matrices holding double elements.
-
doubleBenchmarkPrimitiveOptimized
public static void doubleBenchmarkPrimitiveOptimized(int runs, int rows, int columns, boolean print)Runs a bench on matrices holding double elements.
-
intBenchmark
public static void intBenchmark(int runs, int rows, int columns, java.lang.String kind, boolean print, int initialCapacity, double minLoadFactor, double maxLoadFactor)Runs a bench on matrices holding int elements.
-
intBenchmarkPrimitive
public static void intBenchmarkPrimitive(int runs, int rows, int columns, boolean print)Runs a bench on matrices holding int elements.
-
intBenchmarkPrimitiveOptimized
public static void intBenchmarkPrimitiveOptimized(int runs, int rows, int columns, boolean print)Runs a bench on matrices holding int elements.
-
main
public static void main(java.lang.String[] args)
Benchmarks various methods of this class.
-
-