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

26
LINES

< > BotCompany Repo | #1012166 // Bench concurrency-safely iterating TreeMap [OK, 1 second vs 130 ms]

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

Download Jar. Libraryless. Click here for Pure Java version (951L/7K).

!7

static int n = 1000000;

p {
  TreeMap<S, Bool> map = litcimap();
  repeat n {
    map.put(randomID(), Bool.TRUE);
  }
  
  repeat 5 {
    int i = 0;
    time "Iterating" {
      for (S key : keys(map))
        ++i;
    }
    assertEquals(i, n);
      
    i = 1;
    time "Iterating with higherEntry" {
      S s = map.firstKey();
      while ((s = map.higherKey(s)) != null) ++i;
    }
    assertEquals(i, n);
  }
}

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: #1012166
Snippet name: Bench concurrency-safely iterating TreeMap [OK, 1 second vs 130 ms]
Eternal ID of this version: #1012166/7
Text MD5: 086d854569eeca4260ae3a7e7d48973a
Transpilation MD5: 6709c6790a03471edeabdc577690fcbd
Author: stefan
Category: javax / collections
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-11-23 10:49:02
Source code size: 446 bytes / 26 lines
Pitched / IR pitched: No / No
Views / Downloads: 573 / 1234
Version history: 6 change(s)
Referenced in: [show references]