Created
September 7, 2020 07:40
-
-
Save doom369/8c5777731ed7c815bee5433bc0e0fe15 to your computer and use it in GitHub Desktop.
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
@BenchmarkMode(Mode.AverageTime) | |
@Fork(5) | |
@State(Scope.Thread) | |
@Warmup(iterations = 5, time = 1) | |
@OutputTimeUnit(TimeUnit.NANOSECONDS) | |
@Measurement(iterations = 10, time = 1) | |
public class EnumValueOf { | |
String[] names; | |
int index; | |
@Setup | |
public void init() { | |
WidgetProperty[] values = WidgetProperty.values(); | |
names = new Random(0).ints(4096, 0, values.length) | |
.mapToObj(i -> values[i].name()) | |
.toArray(String[]::new); | |
index = 0; | |
} | |
private String nextName() { | |
return names[index++ & (names.length - 1)]; | |
} | |
@Benchmark | |
public WidgetProperty enumValueOf() { | |
return WidgetProperty.valueOf(nextName()); | |
} | |
@Benchmark | |
public WidgetProperty enumSwitch() { | |
return WidgetProperty.valueOfSwitch(nextName()); | |
} | |
@Benchmark | |
public WidgetProperty enumMap() { | |
return WidgetProperty.valueOfMap(nextName()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment