Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

23
LINES

< > BotCompany Repo | #1009442 // Measure size of TreeMap [gives astonishingly good estimates]

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (427L/4K/12K).

1  
!7
2  
3  
static int n = 20000;
4  
5  
p {
6  
  for (int tableSize = 0; tableSize < 200; tableSize += 20) {
7  
    new L data;
8  
    for i to tableSize: data.add(i);
9  
    O[] array = new O[n];
10  
    long mem1 = usedMemoryAfterGC();
11  
    for i over array: {
12  
      new TreeMap map;
13  
      for (O x : data) map.put(x, x);
14  
      array[i] = map;
15  
    }
16  
    long mem2 = usedMemoryAfterGC();
17  
    double objSize = (mem2-mem1)/(double) l(array);
18  
    int rounded = iround(objSize);
19  
    long f = guessTreeMapSize(tableSize);
20  
    bool ok = rounded == f;
21  
    print((ok ? "OK " : "") + "Hash table size=" + tableSize + ". Approximate object size: " + objSize + " => " + rounded + " bytes. Formula: " + f);
22  
  }
23  
}

Author comment

Began life as a copy of #1009433

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1009442
Snippet name: Measure size of TreeMap [gives astonishingly good estimates]
Eternal ID of this version: #1009442/4
Text MD5: 13818ab8e574fbf966182bc7be5636fb
Transpilation MD5: e41024ccbc7033030470f81c4f8e3af5
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:11:58
Source code size: 693 bytes / 23 lines
Pitched / IR pitched: No / No
Views / Downloads: 398 / 485
Version history: 3 change(s)
Referenced in: [show references]