[jdom-interest] Reference comparisons in SAXHandler.startElem ent

GB/DEV - Philip Nelson philip.nelson at omniresources.com
Wed Mar 14 13:16:34 PST 2001


> == is *ALWAYS* going to be faster than .equals(), because you 
> don't have to
> look up a virtual method, switch context for it, etc. The == 
> operator is an
> atomic JVM opcode.

Yes you are right about that, intern won't make equals() go any faster.  

There seems to be some disagreement about how big the hit is and when it
would hurt most.  In my tests, there was between a 14 and 20% hit for
equals().  vs ==.

> 
> I also think that because the time spent context switching is 
> probably the
> major piece of calling .equals(), a forced call to .intern() 
> is going to
> take almost as long.  It would definitely be nice if we could 
> assume the
> parser has intern()ed for us.

I suppose how often it's called and how much gain for the most typical uses
of xml will decide.  As Jason said, tests should verify these assumptions.




More information about the jdom-interest mailing list