This repository has been archived by the owner on Sep 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
additional comparable parameter
- Loading branch information
Showing
3 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/test/java/cc/neckbeard/tinypubsub/tests/PubSubTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} | ||
|
||
} |