From 8a18913d32c76b1aa8602f231fe77779b3be7f52 Mon Sep 17 00:00:00 2001 From: themode Date: Sat, 1 Jan 2022 19:03:00 +0100 Subject: [PATCH] Improve node test --- .../minestom/jmh/event/SingleNodeBenchmark.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/jmh-benchmarks/src/jmh/java/net/minestom/jmh/event/SingleNodeBenchmark.java b/jmh-benchmarks/src/jmh/java/net/minestom/jmh/event/SingleNodeBenchmark.java index f6b92d8e6..db105aec1 100644 --- a/jmh-benchmarks/src/jmh/java/net/minestom/jmh/event/SingleNodeBenchmark.java +++ b/jmh-benchmarks/src/jmh/java/net/minestom/jmh/event/SingleNodeBenchmark.java @@ -7,8 +7,8 @@ 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) +@Warmup(iterations = 5, time = 1000, timeUnit = TimeUnit.MILLISECONDS) +@Measurement(iterations = 10, time = 1000, timeUnit = TimeUnit.MILLISECONDS) @Fork(3) @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) @@ -24,14 +24,24 @@ public class SingleNodeBenchmark { record TestEvent() implements Event { } + record TestEvent2() implements Event { + } + @Setup public void setup() { node = EventNode.all("node"); for (int i = 0; i < listenerCount; i++) { - node.addListener(TestEvent.class, testEvent -> { + node.addListener(TestEvent.class, e -> { // Empty }); } + // Real-world code are very unlikely to use entirely empty nodes. + // This ensures that the handle map is properly lazily initialized to prevent fast exits. + node.addListener(TestEvent2.class, e -> { + // Empty + }); + node.call(new TestEvent2()); + this.handle = node.getHandle(TestEvent.class); }