[BAEL-2996] Moving all test under this module and adding benchmarking
This commit is contained in:
parent
bc498d61b3
commit
327fc24a4b
@ -119,6 +119,18 @@
|
|||||||
<version>${crawler4j.version}</version>
|
<version>${crawler4j.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Benchmarking -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openjdk.jmh</groupId>
|
||||||
|
<artifactId>jmh-core</artifactId>
|
||||||
|
<version>${jmh.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openjdk.jmh</groupId>
|
||||||
|
<artifactId>jmh-generator-annprocess</artifactId>
|
||||||
|
<version>${jmh.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
@ -133,5 +145,6 @@
|
|||||||
<nd4j.version>1.0.0-beta4</nd4j.version>
|
<nd4j.version>1.0.0-beta4</nd4j.version>
|
||||||
<colt.version>1.2.0</colt.version>
|
<colt.version>1.2.0</colt.version>
|
||||||
<la4j.version>0.6.0</la4j.version>
|
<la4j.version>0.6.0</la4j.version>
|
||||||
|
<jmh.version>1.19</jmh.version>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.baeldung.matrices;
|
||||||
|
|
||||||
|
import org.openjdk.jmh.Main;
|
||||||
|
|
||||||
|
public class MatrixMultiplicationBenchmarking {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
Main.main(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,15 +1,21 @@
|
|||||||
package com.baeldung.commons.math;
|
package com.baeldung.matrices.apache;
|
||||||
|
|
||||||
import org.apache.commons.math3.linear.Array2DRowRealMatrix;
|
import org.apache.commons.math3.linear.Array2DRowRealMatrix;
|
||||||
import org.apache.commons.math3.linear.RealMatrix;
|
import org.apache.commons.math3.linear.RealMatrix;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.openjdk.jmh.annotations.*;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
class RealMatrixUnitTest {
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
@Fork(value = 2)
|
||||||
|
@Warmup(iterations = 5)
|
||||||
|
@Measurement(iterations = 10)
|
||||||
|
public class RealMatrixUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() {
|
@Benchmark
|
||||||
|
public void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() {
|
||||||
RealMatrix firstMatrix = new Array2DRowRealMatrix(
|
RealMatrix firstMatrix = new Array2DRowRealMatrix(
|
||||||
new double[][] {
|
new double[][] {
|
||||||
new double[] {1d, 5d},
|
new double[] {1d, 5d},
|
@ -4,13 +4,19 @@ import cern.colt.matrix.DoubleFactory2D;
|
|||||||
import cern.colt.matrix.DoubleMatrix2D;
|
import cern.colt.matrix.DoubleMatrix2D;
|
||||||
import cern.colt.matrix.linalg.Algebra;
|
import cern.colt.matrix.linalg.Algebra;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.openjdk.jmh.annotations.*;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
class DoubleMatrix2DUnitTest {
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
@Fork(value = 2)
|
||||||
|
@Warmup(iterations = 5)
|
||||||
|
@Measurement(iterations = 10)
|
||||||
|
public class DoubleMatrix2DUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() {
|
@Benchmark
|
||||||
|
public void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() {
|
||||||
DoubleFactory2D doubleFactory2D = DoubleFactory2D.dense;
|
DoubleFactory2D doubleFactory2D = DoubleFactory2D.dense;
|
||||||
|
|
||||||
DoubleMatrix2D firstMatrix = doubleFactory2D.make(
|
DoubleMatrix2D firstMatrix = doubleFactory2D.make(
|
||||||
@ -41,4 +47,5 @@ class DoubleMatrix2DUnitTest {
|
|||||||
|
|
||||||
assertThat(actual).isEqualTo(expected);
|
assertThat(actual).isEqualTo(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,19 @@ package com.baeldung.matrices.ejml;
|
|||||||
|
|
||||||
import org.ejml.simple.SimpleMatrix;
|
import org.ejml.simple.SimpleMatrix;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.openjdk.jmh.annotations.*;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
class SimpleMatrixUnitTest {
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
@Fork(value = 2)
|
||||||
|
@Warmup(iterations = 5)
|
||||||
|
@Measurement(iterations = 10)
|
||||||
|
public class SimpleMatrixUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() {
|
@Benchmark
|
||||||
|
public void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() {
|
||||||
SimpleMatrix firstMatrix = new SimpleMatrix(
|
SimpleMatrix firstMatrix = new SimpleMatrix(
|
||||||
new double[][] {
|
new double[][] {
|
||||||
new double[] {1d, 5d},
|
new double[] {1d, 5d},
|
||||||
@ -36,4 +42,5 @@ class SimpleMatrixUnitTest {
|
|||||||
|
|
||||||
assertThat(actual).matches(m -> m.isIdentical(expected, 0d));
|
assertThat(actual).matches(m -> m.isIdentical(expected, 0d));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,19 @@
|
|||||||
package com.baeldung.matrices.homemade;
|
package com.baeldung.matrices.homemade;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.openjdk.jmh.annotations.*;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
class MatrixUnitTest {
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
@Fork(value = 2)
|
||||||
|
@Warmup(iterations = 5)
|
||||||
|
@Measurement(iterations = 10)
|
||||||
|
public class HomemadeMatrixUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() {
|
@Benchmark
|
||||||
|
public void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() {
|
||||||
double[][] firstMatrix = {
|
double[][] firstMatrix = {
|
||||||
new double[]{1d, 5d},
|
new double[]{1d, 5d},
|
||||||
new double[]{2d, 3d},
|
new double[]{2d, 3d},
|
@ -3,13 +3,19 @@ package com.baeldung.matrices.la4j;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.la4j.Matrix;
|
import org.la4j.Matrix;
|
||||||
import org.la4j.matrix.dense.Basic2DMatrix;
|
import org.la4j.matrix.dense.Basic2DMatrix;
|
||||||
|
import org.openjdk.jmh.annotations.*;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
class Basic2DMatrixUnitTest {
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
@Fork(value = 2)
|
||||||
|
@Warmup(iterations = 5)
|
||||||
|
@Measurement(iterations = 10)
|
||||||
|
public class Basic2DMatrixUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() {
|
@Benchmark
|
||||||
|
public void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() {
|
||||||
Matrix firstMatrix = new Basic2DMatrix(
|
Matrix firstMatrix = new Basic2DMatrix(
|
||||||
new double[][]{
|
new double[][]{
|
||||||
new double[]{1d, 5d},
|
new double[]{1d, 5d},
|
||||||
@ -37,4 +43,5 @@ class Basic2DMatrixUnitTest {
|
|||||||
|
|
||||||
assertThat(actual).isEqualTo(expected);
|
assertThat(actual).isEqualTo(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,13 +3,18 @@ package com.baeldung.matrices.nd4j;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.nd4j.linalg.api.ndarray.INDArray;
|
import org.nd4j.linalg.api.ndarray.INDArray;
|
||||||
import org.nd4j.linalg.factory.Nd4j;
|
import org.nd4j.linalg.factory.Nd4j;
|
||||||
|
import org.openjdk.jmh.annotations.*;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
class INDArrayUnitTest {
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
@Fork(value = 2)
|
||||||
|
@Warmup(iterations = 5)
|
||||||
|
@Measurement(iterations = 10)
|
||||||
|
public class INDArrayUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() {
|
public void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() {
|
||||||
INDArray firstMatrix = Nd4j.create(
|
INDArray firstMatrix = Nd4j.create(
|
||||||
new double[][]{
|
new double[][]{
|
||||||
new double[]{1d, 5d},
|
new double[]{1d, 5d},
|
||||||
@ -37,4 +42,5 @@ class INDArrayUnitTest {
|
|||||||
|
|
||||||
assertThat(actual).isEqualTo(expected);
|
assertThat(actual).isEqualTo(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user