Skip to content

Commit a791058

Browse files
committed
2 04 JMH Benchmark patch
1 parent 9a5bc24 commit a791058

2 files changed

Lines changed: 73 additions & 0 deletions

File tree

pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@
3434
</build>
3535

3636
<dependencies>
37+
<dependency>
38+
<groupId>org.openjdk.jmh</groupId>
39+
<artifactId>jmh-core</artifactId>
40+
<version>RELEASE</version>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.openjdk.jmh</groupId>
44+
<artifactId>jmh-generator-annprocess</artifactId>
45+
<version>RELEASE</version>
46+
<scope>provided</scope>
47+
</dependency>
3748
</dependencies>
3849

3950
<profiles>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package ru.javaops.masterjava.matrix;
2+
3+
import org.openjdk.jmh.annotations.*;
4+
5+
import java.util.concurrent.ExecutorService;
6+
import java.util.concurrent.Executors;
7+
import java.util.concurrent.TimeUnit;
8+
9+
/**
10+
* gkislin
11+
* 23.09.2016
12+
*/
13+
@Warmup(iterations = 10)
14+
@Measurement(iterations = 10)
15+
@BenchmarkMode({Mode.SingleShotTime})
16+
@OutputTimeUnit(TimeUnit.MILLISECONDS)
17+
@State(Scope.Benchmark)
18+
@Threads(1)
19+
@Fork(1)
20+
@Timeout(time = 5, timeUnit = TimeUnit.MINUTES)
21+
public class MatrixBenchmark {
22+
// Matrix size
23+
@Param({"100", "1000"})
24+
private int matrixSize;
25+
26+
private static final int THREAD_NUMBER = 10;
27+
private final static ExecutorService executor = Executors.newFixedThreadPool(THREAD_NUMBER);
28+
29+
private static int[][] matrixA;
30+
private static int[][] matrixB;
31+
32+
@Setup
33+
public void setUp() {
34+
matrixA = MatrixUtil.create(matrixSize);
35+
matrixB = MatrixUtil.create(matrixSize);
36+
}
37+
38+
@Benchmark
39+
public int[][] singleThreadMultiplyOpt() throws Exception {
40+
return MatrixUtil.singleThreadMultiplyOpt(matrixA, matrixB);
41+
}
42+
43+
@Benchmark
44+
public int[][] concurrentMultiplyStreams() throws Exception {
45+
return MatrixUtil.concurrentMultiplyStreams(matrixA, matrixB, executor);
46+
}
47+
48+
@Benchmark
49+
public int[][] concurrentMultiply2() throws Exception {
50+
return MatrixUtil.concurrentMultiply2(matrixA, matrixB, executor);
51+
}
52+
53+
@Benchmark
54+
public int[][] concurrentMultiply3() throws Exception {
55+
return MatrixUtil.concurrentMultiply3(matrixA, matrixB, executor);
56+
}
57+
58+
@TearDown
59+
public void tearDown() {
60+
executor.shutdown();
61+
}
62+
}

0 commit comments

Comments
 (0)