Dmitry,
thanks for the interesting results.
Your results are not as promising as mine.
I guess, referring to the HotSpot's dissassembler dump would give more
hints.
Additionally different string lengths, repeat factors, -Xbatch, and GC
settings would help.
Good trick to use substring(1) for cheap instatiation.
To estimate the instantiation cost you could add:
public int timeInitLong(int reps) {
int dummy = 0;
for (int i = 0; i < reps; i++) {
dummy += LONG.substring(1).offset - 1;
}
return dummy;
}
Do you have any idea, why first hashCode1() warmup is 10 times slower
than hashCode() warmup in my case?
-Ulf
Am 27.02.2010 15:00, schrieb Dmitry Nadezhin:
Ulf,
I ran Caliper benchmarks on different variants of hashCode().
http://code.google.com/p/caliper/
The results and the Caliper code are below:
-Dima
On Sat, Feb 27, 2010 at 2:18 AM, Ulf Zibis <ulf.zi...@gmx.de
<mailto:ulf.zi...@gmx.de>> wrote:
Am 26.02.2010 20:32, schrieb Alan Bateman:
Ulf Zibis wrote:
For these other suggestions it would be great to create
micro-benchmarks and try our your changes.
For now though, as I said, I'm just fixing the method to avoid the
store for the empty string case.
Here the benchmark for my different approaches on non-empty strings:
hashCode() warmup = 38,227 ms
hashCode1() warmup = 323,462 ms
hashCode() time = 12,066 ms
hashCode1() time = 11,620 ms
hashCodes sum = 0
hashCode() warmup = 34,928 ms
hashCode1() warmup = 19,010 ms
hashCode2() warmup = 25,938 ms
hashCode3() warmup = 22,428 ms
hashCode4() warmup = 22,966 ms
hashCode5() warmup = 21,372 ms
hashCode() time = 418,962 ms
hashCode1() time = 306,977 ms
hashCode2() time = 296,899 ms
hashCode3() time = 363,364 ms
hashCode4() time = 286,098 ms
hashCode5() time = 269,519 ms
hashCodes sum = -1427881024
See new revision:
https://java-nio-charset-enhanced.dev.java.net/source/browse/java-nio-charset-enhanced/branches/j7_EUC_TW/src/java/lang/String.java?rev=955&view=markup
<https://java-nio-charset-enhanced.dev.java.net/source/browse/java-nio-charset-enhanced/branches/j7_EUC_TW/src/java/lang/String.java?rev=955&view=markup>
-Ulf