Event loop benchmark
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package ru.core.events;
|
||||
|
||||
import com.carrotsearch.junitbenchmarks.AbstractBenchmark;
|
||||
import com.carrotsearch.junitbenchmarks.BenchmarkOptions;
|
||||
import mc.core.events.LoginEvent;
|
||||
import mc.core.events.SimpleEventLoop;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import ru.core.events.handlers.SampleEventHandler;
|
||||
|
||||
public class SimpleEventLoopBenchmark extends AbstractBenchmark {
|
||||
private static SimpleEventLoop simpleEventLoop;
|
||||
private static LoginEvent testEvent;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup(){
|
||||
simpleEventLoop = new SimpleEventLoop();
|
||||
simpleEventLoop.addEventHandler(new SampleEventHandler());
|
||||
testEvent = new LoginEvent(null);
|
||||
testEvent.setDenyReason("none");
|
||||
}
|
||||
|
||||
@Test
|
||||
@BenchmarkOptions(warmupRounds = 5, benchmarkRounds = 15)
|
||||
public void benchmark() {
|
||||
for (int i = 0; i < 50_000_000; i++) {
|
||||
simpleEventLoop.callEvent(testEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,19 +4,20 @@ import mc.core.events.LoginEvent;
|
||||
import mc.core.events.SimpleEventLoop;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import ru.core.events.handlers.FastEventHandler;
|
||||
import ru.core.events.handlers.SampleEventHandler;
|
||||
|
||||
public class SimpleEventLoopTest {
|
||||
|
||||
@Test
|
||||
public void loopWorks() {
|
||||
SimpleEventLoop simpleEventLoop = new SimpleEventLoop();
|
||||
simpleEventLoop.addEventHandler(new SampleEventHandler());
|
||||
simpleEventLoop.addEventHandler(new FastEventHandler());
|
||||
LoginEvent testEvent = new LoginEvent(null);
|
||||
testEvent.setDenyReason("none");
|
||||
|
||||
simpleEventLoop.callEvent(testEvent);
|
||||
|
||||
Assert.assertEquals("Event handler was not called", "Hello from SampleEventHandler!", testEvent.getDenyReason());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package ru.core.events.handlers;
|
||||
|
||||
import mc.core.events.EventHandler;
|
||||
import mc.core.events.LoginEvent;
|
||||
|
||||
public class FastEventHandler {
|
||||
@EventHandler
|
||||
public void onPlayerLogin(LoginEvent event) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package ru.core.events;
|
||||
package ru.core.events.handlers;
|
||||
|
||||
import mc.core.events.EventHandler;
|
||||
import mc.core.events.LoginEvent;
|
||||
Reference in New Issue
Block a user