From d4eaeffb3017aefb1535bca73f977a9f54a0af11 Mon Sep 17 00:00:00 2001 From: themode Date: Tue, 4 Jan 2022 00:26:01 +0100 Subject: [PATCH] Palette benchmarks --- .../jmh/palette/PaletteBenchmark.java | 38 +++++++++++++++++ .../jmh/palette/PaletteFillBenchmark.java | 42 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 jmh-benchmarks/src/jmh/java/net/minestom/jmh/palette/PaletteBenchmark.java create mode 100644 jmh-benchmarks/src/jmh/java/net/minestom/jmh/palette/PaletteFillBenchmark.java diff --git a/jmh-benchmarks/src/jmh/java/net/minestom/jmh/palette/PaletteBenchmark.java b/jmh-benchmarks/src/jmh/java/net/minestom/jmh/palette/PaletteBenchmark.java new file mode 100644 index 000000000..d78aa4d6d --- /dev/null +++ b/jmh-benchmarks/src/jmh/java/net/minestom/jmh/palette/PaletteBenchmark.java @@ -0,0 +1,38 @@ +package net.minestom.jmh.palette; + +import net.minestom.server.instance.palette.Palette; +import org.openjdk.jmh.annotations.*; + +import java.util.concurrent.TimeUnit; + +@Warmup(iterations = 5, time = 1500, timeUnit = TimeUnit.MILLISECONDS) +@Measurement(iterations = 10, time = 1500, timeUnit = TimeUnit.MILLISECONDS) +@Fork(3) +@BenchmarkMode(Mode.AverageTime) +@OutputTimeUnit(TimeUnit.NANOSECONDS) +@State(Scope.Benchmark) +public class PaletteBenchmark { + + @Param({"4", "8", "16"}) + public int dimension; + + private Palette palette; + + @Setup + public void setup() { + palette = Palette.newPalette(dimension, 15, 4, 1); + } + + @Benchmark + public void loop() { + int value = 0; + final int dimension = palette.dimension(); + for (int y = 0; y < dimension; y++) { + for (int x = 0; x < dimension; x++) { + for (int z = 0; z < dimension; z++) { + palette.set(x, y, z, value++); + } + } + } + } +} diff --git a/jmh-benchmarks/src/jmh/java/net/minestom/jmh/palette/PaletteFillBenchmark.java b/jmh-benchmarks/src/jmh/java/net/minestom/jmh/palette/PaletteFillBenchmark.java new file mode 100644 index 000000000..5f2cc1cf9 --- /dev/null +++ b/jmh-benchmarks/src/jmh/java/net/minestom/jmh/palette/PaletteFillBenchmark.java @@ -0,0 +1,42 @@ +package net.minestom.jmh.palette; + +import net.minestom.server.instance.palette.Palette; +import org.openjdk.jmh.annotations.*; + +import java.util.concurrent.TimeUnit; + +@Warmup(iterations = 5, time = 1500, timeUnit = TimeUnit.MILLISECONDS) +@Measurement(iterations = 10, time = 1500, timeUnit = TimeUnit.MILLISECONDS) +@Fork(3) +@BenchmarkMode(Mode.AverageTime) +@OutputTimeUnit(TimeUnit.NANOSECONDS) +@State(Scope.Benchmark) +public class PaletteFillBenchmark { + + @Param({"4", "8", "16"}) + public int dimension; + + private Palette palette; + + @Setup + public void setup() { + palette = Palette.newPalette(dimension, 15, 4, 1); + } + + @Benchmark + public void loop() { + final int dimension = palette.dimension(); + for (int y = 0; y < dimension; y++) { + for (int x = 0; x < dimension; x++) { + for (int z = 0; z < dimension; z++) { + palette.set(x, y, z, 5); + } + } + } + } + + @Benchmark + public void fill() { + palette.fill(5); + } +}