-
-
Save plevart/edce6f150b881b542cc722ce11424ae3 to your computer and use it in GitHub Desktop.
ClassValue benchmark for variant 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
JDK14: | |
Benchmark Mode Cnt Score Error Units | |
ClassValueBench.testAconstant avgt 10 2.687 ± 0.004 ns/op | |
ClassValueBench.testCcvCcl avgt 10 4.376 ± 0.015 ns/op | |
ClassValueBench.testCcvNcl avgt 10 4.587 ± 0.022 ns/op | |
ClassValueBench.testNcvCcl avgt 10 4.717 ± 0.009 ns/op | |
ClassValueBench.testNcvNcl avgt 10 4.853 ± 0.018 ns/op | |
patched valhalla: | |
Benchmark Mode Cnt Score Error Units | |
ClassValueBench.testAconstant avgt 10 2.665 ± 0.007 ns/op | |
ClassValueBench.testCcvCcl avgt 10 2.664 ± 0.005 ns/op | |
ClassValueBench.testCcvNcl avgt 10 8.057 ± 0.013 ns/op | |
ClassValueBench.testNcvCcl avgt 10 7.929 ± 0.012 ns/op | |
ClassValueBench.testNcvNcl avgt 10 8.530 ± 0.222 ns/op | |
*/ | |
package my.jmh.test; | |
import org.openjdk.jmh.annotations.Benchmark; | |
import org.openjdk.jmh.annotations.BenchmarkMode; | |
import org.openjdk.jmh.annotations.Fork; | |
import org.openjdk.jmh.annotations.Measurement; | |
import org.openjdk.jmh.annotations.Mode; | |
import org.openjdk.jmh.annotations.OutputTimeUnit; | |
import org.openjdk.jmh.annotations.Scope; | |
import org.openjdk.jmh.annotations.State; | |
import org.openjdk.jmh.annotations.Warmup; | |
import java.util.concurrent.TimeUnit; | |
@BenchmarkMode(Mode.AverageTime) | |
@Warmup(iterations = 5, time = 1) | |
@Measurement(iterations = 10, time = 1) | |
@OutputTimeUnit(TimeUnit.NANOSECONDS) | |
@State(Scope.Benchmark) | |
@Fork(value = 1, warmups = 0) | |
public class ClassValueBench { | |
static final ClassValue<String> CCV = new ClassValue<>() { | |
@Override | |
protected String computeValue(Class<?> type) { | |
return type.getName(); | |
} | |
}; | |
static ClassValue<String> NCV = new ClassValue<>() { | |
@Override | |
protected String computeValue(Class<?> type) { | |
return type.getName(); | |
} | |
}; | |
static final Class<String> CCL = String.class; | |
static Class<String> NCL = String.class; | |
@Benchmark | |
public String testAconstant() { | |
return "A constant"; | |
} | |
@Benchmark | |
public String testCcvCcl() { | |
return CCV.get(CCL); | |
} | |
@Benchmark | |
public String testNcvCcl() { | |
return NCV.get(CCL); | |
} | |
@Benchmark | |
public String testCcvNcl() { | |
return CCV.get(NCL); | |
} | |
@Benchmark | |
public String testNcvNcl() { | |
return NCV.get(NCL); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment