Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @State(Scope.Benchmark)
- public class VanillaLong2ObjectHashMap {
- private Long2ObjectMap<String> map;
- private int[][] playersOffsets;
- private int player;
- private int relPosX, relPosY, relPosZ;
- @Setup
- public void setup() {
- map = new Long2ObjectOpenHashMap<>(8192, 0.6f);
- playersOffsets = new int[8*20][2]; // 8 players
- Random rang = new Random(Main.SEED);
- for (int p = 0; p < 8*20; p++) {
- playersOffsets[p][0] = rang.nextInt(6000) - 3000;
- rang.nextInt(6000);
- playersOffsets[p][1] = rang.nextInt(6000) - 3000;
- for (int x = 0; x < 20; x++) {
- for (int z = 0; z < 20; z++) {
- map.put((((long) x + playersOffsets[p][0]) << 32) | (z + playersOffsets[p][1]),
- "This is the value at" + x + ", " + z);
- }
- }
- }
- }
- @Benchmark
- @OutputTimeUnit(value = TimeUnit.MICROSECONDS)
- public void benchmarkGet(Blackhole bh) {
- String str = map.get((((long) playersOffsets[player][0] + relPosX) << 32) | (playersOffsets[player][1] + relPosZ));
- bh.consume(str);
- bh.consume(relPosY);
- relPosX++;
- if (relPosX > 20) {
- relPosY++;
- relPosX = -20;
- if (relPosY > 20) {
- relPosZ++;
- relPosY = -20;
- if (relPosZ > 20) {
- player++;
- relPosZ = -20;
- if (player >= 3) {
- player = 0;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement