tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David kerber <>
Subject Re: Performance: switch vs if ... else if
Date Thu, 21 May 2009 17:57:44 GMT
Christopher Schultz wrote:
> Hash: SHA1
> David,
> On 5/19/2009 3:04 PM, David kerber wrote:
>> I have a section of code in a frequently-called (~3.5 million times
>> per day) servlet where I had to process based on a parameter that
>> could take one of 6 different single-character string values.  I had
>> been using an if .. else if construct.  Then I discovered that java
>> 1.5 allowed constructing a switch on strings.  So I did some speed
>> testing of a standalone java class that compared the 6-option switch
>> that vs my 6-step if/elseif.
> I'd be interested to see what the bytecode looks like. Javac compiles
> switch statements (using primitives) to one of two bytecodes:
> lookupswitch or tableswitch. If you can get the compiler to generate a
> tableswitch, your performance will increase dramatically due to the way
> the bytecode works.
> See
> for more information on these bytecodes.
Interesting.  From that description, depending on how sparse is 
"sparse", there's probably a good chance I'm getting a tableswitch.  Can 
you point me to a byte code interpreter so I could look at this?  Or I 
could just send you the .class file of my test class if you'd prefer.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message