-----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.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkoVlE4ACgkQ9CaO5/Lv0PDzGgCeKdzJpFmzj8uBhaaC99IpSsky
6mQAoMRbUlgGymISSy9AZe79hstWMInR
=/Zfb
-----END PGP SIGNATURE-----

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

Reply via email to