Comment Comment by Calzifer for(int i=0;i<10000; ++i){ // do nothing just compute hash again and again. hash = str.hashCode(); } https://github.com/MayankPratap/Samchika/blob/ebf45acad1963d..."do nothing" is correct, "again and again" not so much. Java caches the hash code for Strings and since the JIT knows that (at least in recent version[1]) it might even remove this loop entirely.[1] https://news.ycombinator.com/item?id=43854337 parent Calzifer 1 year ago
"do nothing" is correct, "again and again" not so much. Java caches the hash code for Strings and since the JIT knows that (at least in recent version[1]) it might even remove this loop entirely.
[1] https://news.ycombinator.com/item?id=43854337