Christopher Schultz wrote:
-----BEGIN PGP SIGNED MESSAGE-----
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
http://java.sun.com/docs/books/jvms/second_edition/html/Compiling.doc.html#14942
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.

D




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to