diff --git a/pom.xml b/pom.xml index 35dff4a..9a7662f 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ cc.neckbeard TinyPubSub - 0.3.0 + 0.3.1 ${project.artifactId} jar diff --git a/src/main/java/cc/neckbeard/tinypubsub/Sub.java b/src/main/java/cc/neckbeard/tinypubsub/Sub.java index 5e5b0b2..df38141 100644 --- a/src/main/java/cc/neckbeard/tinypubsub/Sub.java +++ b/src/main/java/cc/neckbeard/tinypubsub/Sub.java @@ -27,7 +27,10 @@ public int compareTo(@NotNull Sub sub) { if (sub.prio != prio) { return Integer.compare(sub.prio, prio); } - return Integer.compare(sub.consumer.hashCode(), consumer.hashCode()); + if (sub.consumer.hashCode() != consumer.hashCode()) { + return Integer.compare(sub.consumer.hashCode(), consumer.hashCode()); + } + return Integer.compare(sub.hashCode(), hashCode()); } } diff --git a/src/test/java/cc/neckbeard/tinypubsub/tests/PubSubTest.java b/src/test/java/cc/neckbeard/tinypubsub/tests/PubSubTest.java new file mode 100644 index 0000000..7464bce --- /dev/null +++ b/src/test/java/cc/neckbeard/tinypubsub/tests/PubSubTest.java @@ -0,0 +1,50 @@ +package cc.neckbeard.tinypubsub.tests; + +import cc.neckbeard.tinypubsub.Bus; +import cc.neckbeard.tinypubsub.Sub; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.IntStream; +@Execution(ExecutionMode.SAME_THREAD) +public class PubSubTest { + + private static final String event = ""; + private static final Bus bus = new Bus(); + private static int hits = 0; + + @Test + void run() { + + System.out.println("com.github.nothub TinyPubSub 8c9f424f85"); + + final int subs = 1_000; + final int pubs = 1_000; + System.out.println("subs: " + subs); + System.out.println("pubs: " + pubs); + + List> listenerContainers = new ArrayList<>(); + + IntStream.range(0, subs).forEach(i -> listenerContainers.add(new Sub<>(0, s -> hits++))); + + final long start = System.nanoTime(); + + IntStream + .range(0, subs) + .forEach(i -> bus.reg(listenerContainers.get(i))); + + IntStream + .range(0, pubs) + .forEach(i -> bus.pub(event)); + + final long end = System.nanoTime() - start; + + System.out.println("hits: " + hits); + System.out.printf("%,dns (%,dms)", end, end / 1000000); + + } + +}