committed by
Zeger Hendrikse
parent
fdcb6a8cf9
commit
b4d3e23c3e
@@ -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;
|
||||
|
||||
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 {
|
||||
|
||||
@Benchmark
|
||||
public void init() {
|
||||
|
||||
}
|
||||
@State(Scope.Benchmark)
|
||||
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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user