Skip to content

Commit 716956c

Browse files
committed
2 05 JMH main jar
1 parent a791058 commit 716956c

2 files changed

Lines changed: 54 additions & 4 deletions

File tree

pom.xml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,41 @@
3030
<target>${java.version}</target>
3131
</configuration>
3232
</plugin>
33+
<plugin>
34+
<groupId>org.apache.maven.plugins</groupId>
35+
<artifactId>maven-shade-plugin</artifactId>
36+
<version>2.2</version>
37+
<executions>
38+
<execution>
39+
<phase>package</phase>
40+
<goals>
41+
<goal>shade</goal>
42+
</goals>
43+
<configuration>
44+
<finalName>benchmarks</finalName>
45+
<transformers>
46+
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
47+
<mainClass>org.openjdk.jmh.Main</mainClass>
48+
</transformer>
49+
</transformers>
50+
<filters>
51+
<filter>
52+
<!--
53+
Shading signed JARs will fail without this.
54+
http://stackoverflow.com/questions/999489/invalid-signature-file-when-attempting-to-run-a-jar
55+
-->
56+
<artifact>*:*</artifact>
57+
<excludes>
58+
<exclude>META-INF/*.SF</exclude>
59+
<exclude>META-INF/*.DSA</exclude>
60+
<exclude>META-INF/*.RSA</exclude>
61+
</excludes>
62+
</filter>
63+
</filters>
64+
</configuration>
65+
</execution>
66+
</executions>
67+
</plugin>
3368
</plugins>
3469
</build>
3570

src/main/java/ru/javaops/masterjava/matrix/MatrixBenchmark.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package ru.javaops.masterjava.matrix;
22

33
import org.openjdk.jmh.annotations.*;
4+
import org.openjdk.jmh.runner.Runner;
5+
import org.openjdk.jmh.runner.RunnerException;
6+
import org.openjdk.jmh.runner.options.Options;
7+
import org.openjdk.jmh.runner.options.OptionsBuilder;
8+
import org.openjdk.jmh.runner.options.TimeValue;
49

510
import java.util.concurrent.ExecutorService;
611
import java.util.concurrent.Executors;
@@ -16,11 +21,11 @@
1621
@OutputTimeUnit(TimeUnit.MILLISECONDS)
1722
@State(Scope.Benchmark)
1823
@Threads(1)
19-
@Fork(1)
24+
@Fork(10)
2025
@Timeout(time = 5, timeUnit = TimeUnit.MINUTES)
2126
public class MatrixBenchmark {
2227
// Matrix size
23-
@Param({"100", "1000"})
28+
@Param({"1000"})
2429
private int matrixSize;
2530

2631
private static final int THREAD_NUMBER = 10;
@@ -35,12 +40,22 @@ public void setUp() {
3540
matrixB = MatrixUtil.create(matrixSize);
3641
}
3742

38-
@Benchmark
43+
public static void main(String[] args) throws RunnerException {
44+
Options options = new OptionsBuilder()
45+
.include(MatrixBenchmark.class.getSimpleName())
46+
.threads(1)
47+
.forks(10)
48+
.timeout(TimeValue.minutes(5))
49+
.build();
50+
new Runner(options).run();
51+
}
52+
53+
// @Benchmark
3954
public int[][] singleThreadMultiplyOpt() throws Exception {
4055
return MatrixUtil.singleThreadMultiplyOpt(matrixA, matrixB);
4156
}
4257

43-
@Benchmark
58+
// @Benchmark
4459
public int[][] concurrentMultiplyStreams() throws Exception {
4560
return MatrixUtil.concurrentMultiplyStreams(matrixA, matrixB, executor);
4661
}

0 commit comments

Comments
 (0)