Class BenchmarkMatrix2D
Iteration Performance [million method
calls per second] Pentium Pro 200 Mhz, SunJDK 1.2.2, NT, java -classic, 60 times repeating the same iteration |
||||||
Element type
|
Matrix2D type | |||||
.
|
DenseDoubleMatrix2D |
SparseDoubleMatrix2D |
||||
getQuick | 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 iteration |
||||||
Element type
|
Matrix2D type = Java array double[][]
|
|||||
.
|
Unoptimized Form for (int row=0; row invalid input: '<' rows; row++) { for (int col=0; col invalid input: '<' columns; ) { value = m[row][col++]; ... } } |
Optimized Form 1000 x 1000 for (int row=0; row invalid input: '<' rows; row++) { int[] r = matrix[row]; for (int col=0; col invalid input: '<' 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
ConstructorsModifierConstructorDescriptionprotected
Makes this class non instantiable, but still let's others inherit from it. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
doubleBenchmark
(int runs, int rows, int columns, String kind, boolean print, int initialCapacity, double minLoadFactor, double maxLoadFactor) Runs a bench on matrices holding double elements.static void
doubleBenchmarkMult
(int runs, int rows, int columns, String kind, boolean print, int initialCapacity, double minLoadFactor, double maxLoadFactor) Runs a bench on matrices holding double elements.static void
doubleBenchmarkPrimitive
(int runs, int rows, int columns, boolean print) Runs a bench on matrices holding double elements.static void
doubleBenchmarkPrimitiveOptimized
(int runs, int rows, int columns, boolean print) Runs a bench on matrices holding double elements.static void
intBenchmark
(int runs, int rows, int columns, String kind, boolean print, int initialCapacity, double minLoadFactor, double maxLoadFactor) Runs a bench on matrices holding int elements.static void
intBenchmarkPrimitive
(int runs, int rows, int columns, boolean print) Runs a bench on matrices holding int elements.static void
intBenchmarkPrimitiveOptimized
(int runs, int rows, int columns, boolean print) Runs a bench on matrices holding int elements.static void
Benchmarks various methods of this class.
-
Constructor Details
-
BenchmarkMatrix2D
protected BenchmarkMatrix2D()Makes this class non instantiable, but still let's others inherit from it.
-
-
Method Details
-
doubleBenchmark
public static void doubleBenchmark(int runs, int rows, int columns, 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, 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, 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
Benchmarks various methods of this class.
-