Skip to content

Instantly share code, notes, and snippets.

View doom369's full-sized avatar
🛴
Working from home

Dmytro Dumanskiy doom369

🛴
Working from home
View GitHub Profile
@BenchmarkMode(Mode.AverageTime)
@Fork(1)
@State(Scope.Thread)
@Warmup(iterations = 5, time = 1)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Measurement(iterations = 10, time = 1)
public class ReplaceAll {
@Param({"", "somePathNoDoT", "some.Path.With.Dot"})
String value;
JDK 11.0.8, OpenJDK 64-Bit Server VM, 11.0.8+10
Benchmark (strParams) Mode Cnt Score Error Units
EnumValueOf.enumMap LABEL avgt 10 11.749 ± 0.761 ns/op
EnumValueOf.enumMap ON_LABEL avgt 10 11.778 ± 0.306 ns/op
EnumValueOf.enumMap MAX avgt 10 10.517 ± 0.056 ns/op
EnumValueOf.enumSwitch LABEL avgt 80 7.149 ± 0.030 ns/op
EnumValueOf.enumSwitch ON_LABEL avgt 80 7.758 ± 0.077 ns/op
EnumValueOf.enumSwitch MAX avgt 80 6.948 ± 0.083 ns/op
EnumValueOf.enumValueOf LABEL avgt 80 15.659 ± 0.450 ns/op
JDK 11.0.8, OpenJDK 64-Bit Server VM, 11.0.8+10
Benchmark Mode Cnt Score Error Units
EnumValues.enumValuesMethod avgt 10 21.576 ± 0.225 ns/op
EnumValues.enumValuesVariable avgt 10 16.811 ± 0.095 ns/op
@BenchmarkMode(Mode.AverageTime)
@Fork(1)
@State(Scope.Thread)
@Warmup(iterations = 5, time = 1)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Measurement(iterations = 10, time = 1)
public class EnumValues {
@Benchmark
public void enumValuesMethod(Blackhole bh) {
Map<String, T> enumConstantDirectory() {
Map<String, T> directory = enumConstantDirectory;
if (directory == null) {
T[] universe = getEnumConstantsShared();
if (universe == null)
throw new IllegalArgumentException(
getName() + " is not an enum type");
directory = new HashMap<>((int)(universe.length / 0.75f) + 1);
for (T constant : universe) {
directory.put(((Enum<?>)constant).name(), constant);
public static <T extends Enum<T>> T valueOf(Class<T> enumType,
String name) {
T result = enumType.enumConstantDirectory().get(name);
if (result != null)
return result;
if (name == null)
throw new NullPointerException("Name is null");
throw new IllegalArgumentException(
"No enum constant " + enumType.getCanonicalName() + "." + name);
}
JDK 11.0.8, OpenJDK 64-Bit Server VM, 11.0.8+10
Benchmark (strParams) Mode Cnt Score Error Units
EnumValueOf.enumSwitch LABEL avgt 80 7.149 ± 0.030 ns/op
EnumValueOf.enumSwitch ON_LABEL avgt 80 7.758 ± 0.077 ns/op
EnumValueOf.enumSwitch MAX avgt 80 6.948 ± 0.083 ns/op
EnumValueOf.enumValueOf LABEL avgt 80 15.659 ± 0.450 ns/op
EnumValueOf.enumValueOf ON_LABEL avgt 80 14.734 ± 0.542 ns/op
EnumValueOf.enumValueOf MAX avgt 80 15.153 ± 0.578 ns/op
@BenchmarkMode(Mode.AverageTime)
@Fork(1)
@State(Scope.Thread)
@Warmup(iterations = 5, time = 1)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Measurement(iterations = 10, time = 1)
public class EnumValueOf {
@Param({"LABEL", "ON_LABEL", "MAX"})
String strParams;
public static WidgetProperty valueOfSwitch(String value) {
switch (value) {
case "LABEL" :
return WidgetProperty.LABEL;
case "COLOR" :
return WidgetProperty.COLOR;
case "ON_LABEL" :
return WidgetProperty.ON_LABEL;
case "OFF_LABEL" :
return WidgetProperty.OFF_LABEL;
@BenchmarkMode(Mode.AverageTime)
@Fork(value = 1)
@State(Scope.Thread)
@Warmup(iterations = 5, time = 1)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Measurement(iterations = 10, time = 1)
public class StringBuilderChainingFailure {
String[] sqlColumnNames;