Skip to content

Commit b4d3e23

Browse files
dkornishevzhendrikse
authored andcommitted
* JMH * JMH
1 parent fdcb6a8 commit b4d3e23

5 files changed

Lines changed: 104 additions & 103 deletions

File tree

‎jmh/pom.xml‎

Lines changed: 54 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,60 @@
11
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3-
<modelVersion>4.0.0</modelVersion>
4-
<groupId>com.baeldung</groupId>
5-
<artifactId>jmh</artifactId>
6-
<packaging>jar</packaging>
7-
<version>1.0-SNAPSHOT</version>
8-
<name>jmh</name>
9-
<url>http://maven.apache.org</url>
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.baeldung</groupId>
5+
<artifactId>jmh</artifactId>
6+
<packaging>jar</packaging>
7+
<version>1.0-SNAPSHOT</version>
8+
<name>jmh</name>
9+
<url>http://maven.apache.org</url>
1010

11-
<properties>
12-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13-
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
14-
<java.version>1.8</java.version>
15-
</properties>
11+
<properties>
12+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
14+
<java.version>1.8</java.version>
15+
<maven.compiler.source>1.6</maven.compiler.source>
16+
<maven.compiler.target>1.6</maven.compiler.target>
17+
</properties>
1618

17-
<dependencies>
18-
<dependency>
19-
<groupId>org.openjdk.jmh</groupId>
20-
<artifactId>jmh-core</artifactId>
21-
<version>1.19</version>
22-
</dependency>
23-
<dependency>
24-
<groupId>org.openjdk.jmh</groupId>
25-
<artifactId>jmh-generator-annprocess</artifactId>
26-
<version>1.19</version>
27-
</dependency>
28-
<dependency>
29-
<groupId>junit</groupId>
30-
<artifactId>junit</artifactId>
31-
<version>3.8.1</version>
32-
<scope>test</scope>
33-
</dependency>
34-
</dependencies>
19+
<dependencies>
20+
<dependency>
21+
<groupId>org.openjdk.jmh</groupId>
22+
<artifactId>jmh-core</artifactId>
23+
<version>1.19</version>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.openjdk.jmh</groupId>
27+
<artifactId>jmh-generator-annprocess</artifactId>
28+
<version>1.19</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>junit</groupId>
32+
<artifactId>junit</artifactId>
33+
<version>3.8.1</version>
34+
<scope>test</scope>
35+
</dependency>
3536

36-
<build>
37-
<plugins>
38-
<plugin>
39-
<groupId>org.apache.maven.plugins</groupId>
40-
<artifactId>maven-jar-plugin</artifactId>
41-
<configuration>
42-
<archive>
43-
<manifest>
44-
<mainClass>com.baeldung.Application</mainClass>
45-
</manifest>
46-
</archive>
47-
</configuration>
48-
</plugin>
49-
</plugins>
50-
</build>
37+
<dependency>
38+
<groupId>com.google.guava</groupId>
39+
<artifactId>guava</artifactId>
40+
<version>21.0</version>
41+
</dependency>
42+
</dependencies>
43+
44+
<build>
45+
<plugins>
46+
<plugin>
47+
<groupId>org.apache.maven.plugins</groupId>
48+
<artifactId>maven-jar-plugin</artifactId>
49+
<configuration>
50+
<archive>
51+
<manifest>
52+
<mainClass>com.baeldung.BenchmarkRunner</mainClass>
53+
</manifest>
54+
</archive>
55+
</configuration>
56+
</plugin>
57+
</plugins>
58+
</build>
5159

5260
</project>

‎jmh/src/main/java/com/baeldung/Application.java‎

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,48 @@
11
package com.baeldung;
22

3-
import org.openjdk.jmh.annotations.Benchmark;
3+
import com.google.common.hash.HashFunction;
4+
import com.google.common.hash.Hasher;
5+
import com.google.common.hash.Hashing;
6+
import org.openjdk.jmh.annotations.*;
7+
8+
import java.nio.charset.Charset;
49

510
public class BenchMark {
611

7-
@Benchmark
8-
public void init() {
9-
10-
}
12+
@State(Scope.Benchmark)
13+
public static class ExecutionPlan {
14+
15+
@Param({ "100", "200", "300", "500", "1000" })
16+
public int iterations;
17+
18+
public Hasher murmur3;
19+
20+
public String password = "4v3rys3kur3p455w0rd";
21+
22+
@Setup(Level.Invocation)
23+
public void setUp() {
24+
murmur3 = Hashing.murmur3_128().newHasher();
25+
}
26+
}
27+
28+
@Fork(value = 1, warmups = 1)
29+
@Benchmark
30+
@BenchmarkMode(Mode.Throughput)
31+
@Warmup(iterations = 5)
32+
public void benchMurmur3_128(ExecutionPlan plan) {
33+
34+
for (int i = plan.iterations; i > 0; i--) {
35+
plan.murmur3.putString(plan.password, Charset.defaultCharset());
36+
}
37+
38+
plan.murmur3.hash();
39+
}
40+
41+
@Benchmark
42+
@Fork(value = 1, warmups = 1)
43+
@BenchmarkMode(Mode.Throughput)
44+
public void init() {
45+
// Do nothing
46+
}
1147

1248
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.baeldung;
2+
3+
public class BenchmarkRunner {
4+
5+
public static void main(String[] args) throws Exception {
6+
org.openjdk.jmh.Main.main(args);
7+
}
8+
9+
}

‎jmh/src/test/java/com/baeldung/AppTest.java‎

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)