«
^
»
4.8. What is the effect on performance?
I measured the effect on performance by timing the execution of a program.
The program creates a
HashSet
that contains 10000 elements that are objects of the
Date
class.
The program times the execution of 10000 calls of
contains
.
The following times (milliseconds) were obtained:
the code of the
hashCode
method
time taken
return 0;
14826
return iMonth;
1235
return iYear*10000 + iMonth*100 + iDay;
36
Results demonstrate how a carefully chosen
hashCode
method can affect the performance of some programs.