parent
fdcb6a8cf9
commit
b4d3e23c3e
100
jmh/pom.xml
100
jmh/pom.xml
@ -1,52 +1,60 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>jmh</artifactId>
|
<artifactId>jmh</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
<name>jmh</name>
|
<name>jmh</name>
|
||||||
<url>http://maven.apache.org</url>
|
<url>http://maven.apache.org</url>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
</properties>
|
<maven.compiler.source>1.6</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.6</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.openjdk.jmh</groupId>
|
<groupId>org.openjdk.jmh</groupId>
|
||||||
<artifactId>jmh-core</artifactId>
|
<artifactId>jmh-core</artifactId>
|
||||||
<version>1.19</version>
|
<version>1.19</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.openjdk.jmh</groupId>
|
<groupId>org.openjdk.jmh</groupId>
|
||||||
<artifactId>jmh-generator-annprocess</artifactId>
|
<artifactId>jmh-generator-annprocess</artifactId>
|
||||||
<version>1.19</version>
|
<version>1.19</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>3.8.1</version>
|
<version>3.8.1</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
<dependency>
|
||||||
<plugins>
|
<groupId>com.google.guava</groupId>
|
||||||
<plugin>
|
<artifactId>guava</artifactId>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<version>21.0</version>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
</dependency>
|
||||||
<configuration>
|
</dependencies>
|
||||||
<archive>
|
|
||||||
<manifest>
|
<build>
|
||||||
<mainClass>com.baeldung.Application</mainClass>
|
<plugins>
|
||||||
</manifest>
|
<plugin>
|
||||||
</archive>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
</configuration>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
</plugin>
|
<configuration>
|
||||||
</plugins>
|
<archive>
|
||||||
</build>
|
<manifest>
|
||||||
|
<mainClass>com.baeldung.BenchmarkRunner</mainClass>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -1,14 +0,0 @@
|
|||||||
package com.baeldung;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.openjdk.jmh.Main;
|
|
||||||
import org.openjdk.jmh.runner.RunnerException;
|
|
||||||
|
|
||||||
public class Application {
|
|
||||||
|
|
||||||
public static void main(String[] args) throws RunnerException, IOException {
|
|
||||||
Main.main(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,12 +1,48 @@
|
|||||||
package com.baeldung;
|
package com.baeldung;
|
||||||
|
|
||||||
import org.openjdk.jmh.annotations.Benchmark;
|
import com.google.common.hash.HashFunction;
|
||||||
|
import com.google.common.hash.Hasher;
|
||||||
|
import com.google.common.hash.Hashing;
|
||||||
|
import org.openjdk.jmh.annotations.*;
|
||||||
|
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
public class BenchMark {
|
public class BenchMark {
|
||||||
|
|
||||||
@Benchmark
|
@State(Scope.Benchmark)
|
||||||
public void init() {
|
public static class ExecutionPlan {
|
||||||
|
|
||||||
}
|
@Param({ "100", "200", "300", "500", "1000" })
|
||||||
|
public int iterations;
|
||||||
|
|
||||||
|
public Hasher murmur3;
|
||||||
|
|
||||||
|
public String password = "4v3rys3kur3p455w0rd";
|
||||||
|
|
||||||
|
@Setup(Level.Invocation)
|
||||||
|
public void setUp() {
|
||||||
|
murmur3 = Hashing.murmur3_128().newHasher();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Fork(value = 1, warmups = 1)
|
||||||
|
@Benchmark
|
||||||
|
@BenchmarkMode(Mode.Throughput)
|
||||||
|
@Warmup(iterations = 5)
|
||||||
|
public void benchMurmur3_128(ExecutionPlan plan) {
|
||||||
|
|
||||||
|
for (int i = plan.iterations; i > 0; i--) {
|
||||||
|
plan.murmur3.putString(plan.password, Charset.defaultCharset());
|
||||||
|
}
|
||||||
|
|
||||||
|
plan.murmur3.hash();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
@Fork(value = 1, warmups = 1)
|
||||||
|
@BenchmarkMode(Mode.Throughput)
|
||||||
|
public void init() {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
9
jmh/src/main/java/com/baeldung/BenchmarkRunner.java
Normal file
9
jmh/src/main/java/com/baeldung/BenchmarkRunner.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package com.baeldung;
|
||||||
|
|
||||||
|
public class BenchmarkRunner {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
org.openjdk.jmh.Main.main(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,38 +0,0 @@
|
|||||||
package com.baeldung;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
import junit.framework.TestSuite;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unit test for simple App.
|
|
||||||
*/
|
|
||||||
public class AppTest
|
|
||||||
extends TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Create the test case
|
|
||||||
*
|
|
||||||
* @param testName name of the test case
|
|
||||||
*/
|
|
||||||
public AppTest( String testName )
|
|
||||||
{
|
|
||||||
super( testName );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the suite of tests being tested
|
|
||||||
*/
|
|
||||||
public static Test suite()
|
|
||||||
{
|
|
||||||
return new TestSuite( AppTest.class );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rigourous Test :-)
|
|
||||||
*/
|
|
||||||
public void testApp()
|
|
||||||
{
|
|
||||||
assertTrue( true );
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user