Advertisement
Barteks2x

Untitled

Oct 13th, 2016
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. @State(Scope.Benchmark)
  2. public class VanillaLong2ObjectHashMap {
  3.  
  4.     private Long2ObjectMap<String> map;
  5.  
  6.     private int[][] playersOffsets;
  7.  
  8.     private int player;
  9.  
  10.     private int relPosX, relPosY, relPosZ;
  11.  
  12.     @Setup
  13.     public void setup() {
  14.         map = new Long2ObjectOpenHashMap<>(8192, 0.6f);
  15.  
  16.         playersOffsets = new int[8*20][2]; // 8 players
  17.         Random rang = new Random(Main.SEED);
  18.         for (int p = 0; p < 8*20; p++) {
  19.             playersOffsets[p][0] = rang.nextInt(6000) - 3000;
  20.             rang.nextInt(6000);
  21.             playersOffsets[p][1] = rang.nextInt(6000) - 3000;
  22.  
  23.             for (int x = 0; x < 20; x++) {
  24.                 for (int z = 0; z < 20; z++) {
  25.                     map.put((((long) x + playersOffsets[p][0]) << 32) | (z + playersOffsets[p][1]),
  26.                             "This is the value at" + x + ", " + z);
  27.                 }
  28.             }
  29.         }
  30.     }
  31.  
  32.     @Benchmark
  33.     @OutputTimeUnit(value = TimeUnit.MICROSECONDS)
  34.     public void benchmarkGet(Blackhole bh) {
  35.         String str = map.get((((long) playersOffsets[player][0] + relPosX) << 32) | (playersOffsets[player][1] + relPosZ));
  36.         bh.consume(str);
  37.         bh.consume(relPosY);
  38.         relPosX++;
  39.         if (relPosX > 20) {
  40.             relPosY++;
  41.             relPosX = -20;
  42.             if (relPosY > 20) {
  43.                 relPosZ++;
  44.                 relPosY = -20;
  45.                 if (relPosZ > 20) {
  46.                     player++;
  47.                     relPosZ = -20;
  48.                     if (player >= 3) {
  49.                         player = 0;
  50.                     }
  51.                 }
  52.             }
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement