Add nbt case for tag bench

This commit is contained in:
themode 2022-03-23 05:46:59 +01:00
parent 0bd266da23
commit f2674b191a
1 changed files with 15 additions and 3 deletions

View File

@ -2,9 +2,12 @@ package net.minestom.jmh.tag;
import net.minestom.server.tag.Tag;
import net.minestom.server.tag.TagHandler;
import org.jglrxavpok.hephaistos.nbt.NBT;
import org.jglrxavpok.hephaistos.nbt.mutable.MutableNBTCompound;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
@Warmup(iterations = 5, time = 1000, timeUnit = TimeUnit.MILLISECONDS)
@ -22,13 +25,17 @@ public class TagReadBenchmark {
TagHandler tagHandler;
Tag<String> secondTag;
MutableNBTCompound compound;
@Setup
public void setup() {
// Tag benchmark
this.tagHandler = TagHandler.newHandler();
if (present) {
tagHandler.setTag(TAG, "value");
}
if (present) tagHandler.setTag(TAG, "value");
secondTag = Tag.String("key");
// NBT benchmark
this.compound = new MutableNBTCompound(new ConcurrentHashMap<>());
if (present) compound.set("key", NBT.String("value"));
}
@Benchmark
@ -45,4 +52,9 @@ public class TagReadBenchmark {
public void readNewTag(Blackhole blackhole) {
blackhole.consume(tagHandler.getTag(Tag.String("key")));
}
@Benchmark
public void readConstantTagFromCompound(Blackhole blackhole) {
blackhole.consume(compound.getString("key"));
}
}