string hash performance
Jeff Sturm
jsturm@one-point.com
Wed Aug 7 20:23:00 GMT 2002
On Wed, 7 Aug 2002, Jeff Sturm wrote:
> On Wed, 7 Aug 2002, Boehm, Hans wrote:
> > Is it surprising that the IBM JDK would cache the hashCode?
>> Perhaps not. However if it were cached I'd expect it to be about as
fast
> as String.length(). My first tests revealed something like 16us for length()
> vs. 34us for hashCode(). So I figured it might be doing a little more
> than just returning an instance field.
Forgot the test & conditional branch. Duh. Never mind... must get sleep.
I still don't understand why the JDK hashCode would be slower than libgcj
by a factor of 20. The algorithm is simple. Even if the JIT used an integer
multiply in place of shift+add it shouldn't be more than 2-3x slower.
But I'm not complaining...
Jeff
More information about the Java
mailing list