Add tag write bench

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2022-03-27 10:56:54 +02:00
parent fb5d6b88e3
commit c7ee6cecf3
2 changed files with 95 additions and 0 deletions

View File

@ -0,0 +1,56 @@
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 java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
@Warmup(iterations = 5, time = 1000, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = 10, time = 1000, timeUnit = TimeUnit.MILLISECONDS)
@Fork(3)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Benchmark)
public class TagWriteBenchmark {
static final Tag<String> TAG = Tag.String("key");
TagHandler tagHandler;
Tag<String> secondTag;
MutableNBTCompound compound;
@Setup
public void setup() {
// Tag benchmark
this.tagHandler = TagHandler.newHandler();
tagHandler.setTag(TAG, "value");
secondTag = Tag.String("key");
// NBT benchmark
this.compound = new MutableNBTCompound(new ConcurrentHashMap<>());
compound.set("key", NBT.String("value"));
}
@Benchmark
public void writeConstantTag() {
tagHandler.setTag(TAG, "value");
}
@Benchmark
public void writeDifferentTag() {
tagHandler.setTag(secondTag, "value");
}
@Benchmark
public void writeNewTag() {
tagHandler.setTag(Tag.String("key"), "value");
}
@Benchmark
public void writeConstantTagFromCompound() {
compound.setString("key", "value");
}
}

View File

@ -0,0 +1,39 @@
package net.minestom.jmh.tag;
import net.minestom.server.tag.Tag;
import net.minestom.server.tag.TagHandler;
import org.openjdk.jmh.annotations.*;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
@Warmup(iterations = 5, time = 1000, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = 10, time = 1000, timeUnit = TimeUnit.MILLISECONDS)
@Fork(3)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Benchmark)
public class TagWritePathBenchmark {
@Param({"0", "1", "2", "3"})
public int scope;
TagHandler tagHandler;
Tag<String> tag;
@Setup
public void setup() {
this.tagHandler = TagHandler.newHandler();
List<String> path = new ArrayList<>(scope);
for (int i = 0; i < scope; i++) path.add("key" + i);
this.tag = Tag.String("key").path(path.toArray(String[]::new));
tagHandler.setTag(tag, "value");
}
@Benchmark
public void write() {
tagHandler.setTag(tag, "value");
}
}