-
Bug
-
Resolution: Fixed
-
P4
-
5.0
-
b71
-
x86
-
windows_xp
A DESCRIPTION OF THE REQUEST :
Enum.hashCode() call System.identityHashCode() that
is seven times slower than Object.hashCode().
Note that I don't know why and perhaps, System.identityHashCode()
may be optimized.
JUSTIFICATION :
it's improve performance
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
public final int hashCode() {
return super.hashCode();
}
ACTUAL -
public final int hashCode() {
return System.identityHashCode(this);
}
---------- BEGIN SOURCE ----------
It's just a micro benchmark than test super.hashCode()
and System.identityHashCode(this)
/**
* @author remi
*
*/
public class MyEnumTest {
static class Zuper {
public final int hashCode() {
return super.hashCode();
}
}
static class Identity {
public final int hashCode() {
return System.identityHashCode(this);
}
}
static long test(Object o) {
long time=System.nanoTime();
for(int i=0;i<1000000;i++)
o.hashCode();
return System.nanoTime()-time;
}
public static void main(String[] args) {
System.out.println("super "+test(new Zuper()));
System.out.println("identity "+test(new Identity()));
}
}
---------- END SOURCE ----------
###@###.### 10/21/04 23:26 GMT
Enum.hashCode() call System.identityHashCode() that
is seven times slower than Object.hashCode().
Note that I don't know why and perhaps, System.identityHashCode()
may be optimized.
JUSTIFICATION :
it's improve performance
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
public final int hashCode() {
return super.hashCode();
}
ACTUAL -
public final int hashCode() {
return System.identityHashCode(this);
}
---------- BEGIN SOURCE ----------
It's just a micro benchmark than test super.hashCode()
and System.identityHashCode(this)
/**
* @author remi
*
*/
public class MyEnumTest {
static class Zuper {
public final int hashCode() {
return super.hashCode();
}
}
static class Identity {
public final int hashCode() {
return System.identityHashCode(this);
}
}
static long test(Object o) {
long time=System.nanoTime();
for(int i=0;i<1000000;i++)
o.hashCode();
return System.nanoTime()-time;
}
public static void main(String[] args) {
System.out.println("super "+test(new Zuper()));
System.out.println("identity "+test(new Identity()));
}
}
---------- END SOURCE ----------
###@###.### 10/21/04 23:26 GMT
- relates to
-
JDK-6195753 (coll) Arrays.sort(Object[]) should eschew clone() in favor of new Object[]+System.arraycopy()
-
- Closed
-
-
JDK-6378256 Performance problem with System.identityHashCode in client compiler
-
- Resolved
-