Libraryless. Click here for Pure Java version (430L/4K/12K).
1 | !7 |
2 | |
3 | static int n = 20000; |
4 | |
5 | p { |
6 | for (int tableSize = 0; tableSize < 100; tableSize += 10) { |
7 | O[] data = arrayOfBlankObjects(tableSize); |
8 | O[] array = new O[n]; |
9 | long mem1 = usedMemoryAfterGC(); |
10 | for i over array: { |
11 | new HashMap hashMap; |
12 | for (O x : data) hashMap.put(x, x); |
13 | array[i] = hashMap; |
14 | } |
15 | long mem2 = usedMemoryAfterGC(); |
16 | double objSize = (mem2-mem1)/(double) l(array); |
17 | int rounded = iround(objSize); |
18 | long f = guessHashMapSize(tableSize); |
19 | print("Hash table size=" + tableSize + ". Approximate object size: " + objSize + " => " + rounded + " bytes. Formula: " + f); |
20 | } |
21 | } |
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: | 497 / 621 |
Version history: | 5 change(s) |
Referenced in: | [show references] |