-
Bug
-
Resolution: Fixed
-
P3
-
21, 22
-
b26
Consider code like:
```
void test(Object o) {
switch (o) {
case X1 -> {}
case X2 -> {}
...(about 100 cases)
```
this is much slower that writing this as:
``
void test(Object o) {
if (o instanceof X1) {}
else if (o instanceof X2) {}
...(about 100 cases)
```
Attached is a JMH test, which gives these results:
MyBenchmark.testIfElse100 thrpt 5 512697.015 ± 19581.020 ops/s
MyBenchmark.testSwitch100 thrpt 5 31815.371 ± 261.291 ops/s
I.e. the switch is 15+ times slower than the if-else cascade.
```
void test(Object o) {
switch (o) {
case X1 -> {}
case X2 -> {}
...(about 100 cases)
```
this is much slower that writing this as:
``
void test(Object o) {
if (o instanceof X1) {}
else if (o instanceof X2) {}
...(about 100 cases)
```
Attached is a JMH test, which gives these results:
MyBenchmark.testIfElse100 thrpt 5 512697.015 ± 19581.020 ops/s
MyBenchmark.testSwitch100 thrpt 5 31815.371 ± 261.291 ops/s
I.e. the switch is 15+ times slower than the if-else cascade.
- relates to
-
JDK-8335274 SwitchBootstraps.ResolvedEnumLabels.resolvedEnum should be final
- Resolved
-
JDK-8322726 C2: Unloaded signature class kills argument value
- Closed