-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2_04_JMH_Benchmark.patch
More file actions
113 lines (111 loc) · 3.39 KB
/
Copy path2_04_JMH_Benchmark.patch
File metadata and controls
113 lines (111 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
Index: src/main/java/ru/javaops/masterjava/matrix/MatrixBenchmark.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/java/ru/javaops/masterjava/matrix/MatrixBenchmark.java (revision )
+++ src/main/java/ru/javaops/masterjava/matrix/MatrixBenchmark.java (revision )
@@ -0,0 +1,70 @@
+package ru.javaops.masterjava.matrix;
+
+import org.openjdk.jmh.annotations.*;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+@Warmup(iterations = 10)
+@Measurement(iterations = 10)
+@BenchmarkMode({Mode.SingleShotTime})
+@OutputTimeUnit(TimeUnit.MILLISECONDS)
+@State(Scope.Benchmark)
+@Threads(1)
+@Fork(10)
+@Timeout(time = 5, timeUnit = TimeUnit.MINUTES)
+public class MatrixBenchmark {
+
+ // Matrix size
+ private static final int MATRIX_SIZE = 1000;
+
+ @Param({"3", "4", "10"})
+ private int threadNumber;
+
+ private static int[][] matrixA;
+ private static int[][] matrixB;
+
+ @Setup
+ public void setUp() {
+ matrixA = MatrixUtil.create(MATRIX_SIZE);
+ matrixB = MatrixUtil.create(MATRIX_SIZE);
+ }
+
+ private ExecutorService executor;
+
+ // @Benchmark
+ public int[][] singleThreadMultiplyOpt() throws Exception {
+ return MatrixUtil.singleThreadMultiplyOpt(matrixA, matrixB);
+ }
+
+ // @Benchmark
+ public int[][] singleThreadMultiplyOpt2() throws Exception {
+ return MatrixUtil.singleThreadMultiplyOpt(matrixA, matrixB);
+ }
+
+ @Benchmark
+ public int[][] concurrentMultiplyStreams() throws Exception {
+ return MatrixUtil.concurrentMultiplyStreams(matrixA, matrixB, threadNumber);
+ }
+
+ // @Benchmark
+ public int[][] concurrentMultiply() throws Exception {
+ return MatrixUtil.concurrentMultiply(matrixA, matrixB, executor);
+ }
+
+ @Benchmark
+ public int[][] concurrentMultiply2() throws Exception {
+ return MatrixUtil.concurrentMultiply2(matrixA, matrixB, executor);
+ }
+
+ @Setup
+ public void setup() {
+ executor = Executors.newFixedThreadPool(threadNumber);
+ }
+
+ @TearDown
+ public void tearDown() {
+ executor.shutdown();
+ }
+}
\ No newline at end of file
Index: pom.xml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- pom.xml (date 1508790464000)
+++ pom.xml (revision )
@@ -24,7 +24,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
- <version>3.1</version>
+ <version>3.7.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
@@ -34,6 +34,17 @@
</build>
<dependencies>
+ <dependency>
+ <groupId>org.openjdk.jmh</groupId>
+ <artifactId>jmh-core</artifactId>
+ <version>RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>org.openjdk.jmh</groupId>
+ <artifactId>jmh-generator-annprocess</artifactId>
+ <version>RELEASE</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
<profiles>