The problem you have is you are creating lots of objects, triggering lots of GCs and this is slowing your down, but in a random way.
If you perform a System.gc() at the start of each test and increase the size of the young generation to say 1 GB, you can get this
testHashMapWithoutSize:258testHashMapWithoutSize:177testHashMapWithoutSize:158testHashMapWithoutSize:153testHashMapWithoutSize:152testHashMapWithoutSize:151testHashMapWithoutSize:152testHashMapWithoutSize:150testHashMapWithoutSize:158testHashMapWithoutSize:152testHashMapWithSize:89testHashMapWithSize:80testHashMapWithSize:81testHashMapWithSize:85testHashMapWithSize:80testHashMapWithSize:79testHashMapWithSize:87testHashMapWithSize:80testHashMapWithSize:81testHashMapWithSize:86where the tests are run with the options -Xmn1g -Xmx2g and you have
public void testHashMapWihtoutSize(int size) { System.gc(); // before each test to reduce the impact of the GC.In reality you will get GCs in real programs but this helps show you what the problem is.
EDIT In the same test you can do this
public void testTIntObjectHashMapWithSize(int size) { System.gc(); String var = "asdf43trsdg345t"; long ts = System.currentTimeMillis(); TIntObjectHashMapprints
testHashMapWithoutSize:155testHashMapWithSize:77testTIntObjectHashMapWithSize:57testMyIntObjectMapWithSize:8testHashMapWithoutSize:157testHashMapWithSize:78testTIntObjectHashMapWithSize:56testMyIntObjectMapWithSize:7testHashMapWithoutSize:161testHashMapWithSize:79testTIntObjectHashMapWithSize:57testMyIntObjectMapWithSize:7testHashMapWithoutSize:157testHashMapWithSize:78testTIntObjectHashMapWithSize:58testMyIntObjectMapWithSize:7
ليست هناك تعليقات:
إرسال تعليق