From: Leo U. <leo...@ya...> - 2006-12-21 20:34:22
|
I was looking at PyStringMap and it uses: System.identityHashCode(a native method, yuck) as part of its index calculation. From my understanding, Strings are generally interned in Jython, so it should be cheap to call a hashCode on a particular String. According to the JDK String, its hashCode is calculated once so after that it essentially is a simple method call to access a variable. Here is some output from a Test I put together that compared the performance of hashCode vs System.identityHashCode. ONE: 106 TWO: 8 ONE: 117 TWO: 8 ONE: 115 TWO: 8 ONE: 116 TWO: 7 ONE: 116 TWO: 8 ONE: 115 TWO: 7 ONE: 115 TWO: 7 ONE: 115 TWO: 8 ONE: 114 TWO: 8 ONE: 115 TWO: 8 ONE is System.identityHashCode TWO is hashCode note, hashCode is called before the test/looping. So it seems that hashCode is about 16 times faster than that identityHashCode. I guess the question is, would it make sense to investigate PyStringMap to see if it can be redone to get more efficient indexing?(If possible) leouser __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com |