Switch vs if ?

Kirk Pepperdine kirk at kodewerk.com
Tue Jan 16 10:26:50 UTC 2018


I have an exercise in my workshop where the solution can use either a switch statement or if statements. IME there is absolutely no measurable difference between using either technique since JDK 1.6…. so.. my advice is, write readable code.

Kind regards,
Kirk Pepperdine

> On Jan 16, 2018, at 10:41 AM, Laurent Bourgès <bourges.laurent at gmail.com> wrote:
> 
> Hi,
> 
> I ask you as you are the hotspot & jvm performance experts.
> 
> Do you know if hotspot prefers if over switch on integer values (profiling hotspots) ?
> 
> Is it worth to order integer cases with higher probability first or not ?
> 
> How to optimize such if cascades ?
> 
> Cheers,
> Laurent



More information about the hotspot-compiler-dev mailing list