BASE-4618: Use JMH benchmark tool
This commit is contained in:
parent
f0ee9ddf02
commit
c8b3ecbd36
@ -16,6 +16,20 @@
|
|||||||
<relativePath>../</relativePath>
|
<relativePath>../</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openjdk.jmh</groupId>
|
||||||
|
<artifactId>jmh-core</artifactId>
|
||||||
|
<version>${jmh.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openjdk.jmh</groupId>
|
||||||
|
<artifactId>jmh-generator-annprocess</artifactId>
|
||||||
|
<version>${jmh.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<finalName>core-java-lang-4</finalName>
|
<finalName>core-java-lang-4</finalName>
|
||||||
<resources>
|
<resources>
|
||||||
@ -26,4 +40,8 @@
|
|||||||
</resources>
|
</resources>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<jmh.version>1.28</jmh.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -0,0 +1,34 @@
|
|||||||
|
package com.baeldung.finalkeyword;
|
||||||
|
|
||||||
|
import org.openjdk.jmh.annotations.Benchmark;
|
||||||
|
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||||
|
import org.openjdk.jmh.annotations.Mode;
|
||||||
|
import org.openjdk.jmh.annotations.OutputTimeUnit;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public class BenchmarkRunner {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
org.openjdk.jmh.Main.main(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||||
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
public static String concatNonFinalStrings() {
|
||||||
|
String x = "x";
|
||||||
|
String y = "y";
|
||||||
|
return x + y;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||||
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
public static String concatFinalStrings() {
|
||||||
|
final String x = "x";
|
||||||
|
final String y = "y";
|
||||||
|
return x + y;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,22 +0,0 @@
|
|||||||
package com.baeldung.finalkeyword;
|
|
||||||
|
|
||||||
public class LocalVariableFinal {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
for (int i = 0; i < 1500; i++) {
|
|
||||||
long startTime = System.nanoTime();
|
|
||||||
String result = concatStrings();
|
|
||||||
long totalTime = System.nanoTime() - startTime;
|
|
||||||
if (i >= 500) {
|
|
||||||
System.out.println(totalTime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String concatStrings() {
|
|
||||||
final String x = "x";
|
|
||||||
final String y = "y";
|
|
||||||
return x + y;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
package com.baeldung.finalkeyword;
|
|
||||||
|
|
||||||
public class LocalVariableNonFinal {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
for (int i = 0; i < 1500; i++) {
|
|
||||||
long startTime = System.nanoTime();
|
|
||||||
String result = concatStrings();
|
|
||||||
long totalTime = System.nanoTime() - startTime;
|
|
||||||
if (i >= 500) {
|
|
||||||
System.out.println(totalTime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String concatStrings() {
|
|
||||||
String x = "x";
|
|
||||||
String y = "y";
|
|
||||||
return x + y;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user