Libraryless. Click here for Pure Java version (430L/4K/12K).
!7 static int n = 20000; p { for (int tableSize = 0; tableSize < 100; tableSize += 10) { O[] data = arrayOfBlankObjects(tableSize); O[] array = new O[n]; long mem1 = usedMemoryAfterGC(); for i over array: { new HashMap hashMap; for (O x : data) hashMap.put(x, x); array[i] = hashMap; } long mem2 = usedMemoryAfterGC(); double objSize = (mem2-mem1)/(double) l(array); int rounded = iround(objSize); long f = guessHashMapSize(tableSize); print("Hash table size=" + tableSize + ". Approximate object size: " + objSize + " => " + rounded + " bytes. Formula: " + f); } }
Began life as a copy of #1009423
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, wtqryiryparv
No comments. add comment
Snippet ID: | #1009433 |
Snippet name: | Measure size of HashMap [gives a good rough estimate] |
Eternal ID of this version: | #1009433/6 |
Text MD5: | 390e276ef3a79a53ddcb4fe0ac3670ad |
Transpilation MD5: | a11a7f920c75be42028f9f399c422bd6 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-08-01 20:05:33 |
Source code size: | 649 bytes / 21 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 496 / 619 |
Version history: | 5 change(s) |
Referenced in: | [show references] |