Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
0.3.1
Browse files Browse the repository at this point in the history
additional comparable parameter
  • Loading branch information
nothub committed Feb 9, 2021
1 parent 1146a62 commit f639e5e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>cc.neckbeard</groupId>
<artifactId>TinyPubSub</artifactId>
<version>0.3.0</version>
<version>0.3.1</version>

<name>${project.artifactId}</name>
<packaging>jar</packaging>
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/cc/neckbeard/tinypubsub/Sub.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ public int compareTo(@NotNull Sub<T> 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());
}

}
50 changes: 50 additions & 0 deletions src/test/java/cc/neckbeard/tinypubsub/tests/PubSubTest.java
Original file line number Diff line number Diff line change
@@ -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<Sub<String>> 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);

}

}

0 comments on commit f639e5e

Please sign in to comment.