Hello i have two samples of code
if/else if/else statements
private Object getObj(message) {
if (message
A couple of days ago I ran a thorough performance analysis. There's a huge performance impact. With AdoptOpenJDK, if
statements are up to 10 times faster. When the JIT compiler runs hot, this reduces to a 20% penalty.
GraalVM does a better job: 3 times slowdown with the cold JVM, and after giving the compiler enough time to do its magic, there's also a 20% performance penalty.
However, the real question is which version is better for reading and maintaining the application. If you're like me, it's easier to read the if
statement, but there are also people preferring the functional approach.
If you're ready for a deep, deep dive, I invite you to read my detailed analysis about the performance and the implementation of Optional.orElseGet()
and its friends.