Added benchmarks for simple & redirect command execution
This commit is contained in:
parent
6f04756d34
commit
5a8a8a29d2
3 changed files with 82 additions and 0 deletions
|
@ -23,6 +23,8 @@ dependencies {
|
||||||
testImplementation 'org.hamcrest:hamcrest-library:1.2.1'
|
testImplementation 'org.hamcrest:hamcrest-library:1.2.1'
|
||||||
testImplementation 'org.mockito:mockito-core:1.8.5'
|
testImplementation 'org.mockito:mockito-core:1.8.5'
|
||||||
testImplementation 'com.google.guava:guava-testlib:21.0'
|
testImplementation 'com.google.guava:guava-testlib:21.0'
|
||||||
|
testImplementation 'org.openjdk.jmh:jmh-core:1.19'
|
||||||
|
testImplementation 'org.openjdk.jmh:jmh-generator-annprocess:1.19'
|
||||||
}
|
}
|
||||||
|
|
||||||
task sourcesJar(type: Jar) {
|
task sourcesJar(type: Jar) {
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
package com.mojang.brigadier.benchmarks;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
|
import com.mojang.brigadier.ParseResults;
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
|
import org.openjdk.jmh.annotations.Benchmark;
|
||||||
|
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||||
|
import org.openjdk.jmh.annotations.Mode;
|
||||||
|
import org.openjdk.jmh.annotations.OutputTimeUnit;
|
||||||
|
import org.openjdk.jmh.annotations.Scope;
|
||||||
|
import org.openjdk.jmh.annotations.Setup;
|
||||||
|
import org.openjdk.jmh.annotations.State;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static com.mojang.brigadier.builder.LiteralArgumentBuilder.literal;
|
||||||
|
|
||||||
|
@State(Scope.Benchmark)
|
||||||
|
public class RedirectedCommand {
|
||||||
|
private CommandDispatcher<Object> dispatcher;
|
||||||
|
private ParseResults<Object> parse;
|
||||||
|
|
||||||
|
public static void main(final String[] args) throws CommandSyntaxException {
|
||||||
|
final RedirectedCommand command = new RedirectedCommand();
|
||||||
|
command.setup();
|
||||||
|
command.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Setup
|
||||||
|
public void setup() {
|
||||||
|
dispatcher = new CommandDispatcher<>();
|
||||||
|
dispatcher.register(literal("command").executes(c -> 0));
|
||||||
|
dispatcher.register(literal("redirect").redirect(dispatcher.getRoot()));
|
||||||
|
parse = dispatcher.parse("redirect command", new Object());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||||
|
public void execute() throws CommandSyntaxException {
|
||||||
|
dispatcher.execute(parse);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.mojang.brigadier.benchmarks;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
|
import com.mojang.brigadier.ParseResults;
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import org.openjdk.jmh.annotations.Benchmark;
|
||||||
|
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||||
|
import org.openjdk.jmh.annotations.Mode;
|
||||||
|
import org.openjdk.jmh.annotations.OutputTimeUnit;
|
||||||
|
import org.openjdk.jmh.annotations.Scope;
|
||||||
|
import org.openjdk.jmh.annotations.Setup;
|
||||||
|
import org.openjdk.jmh.annotations.State;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static com.mojang.brigadier.builder.LiteralArgumentBuilder.literal;
|
||||||
|
|
||||||
|
@State(Scope.Benchmark)
|
||||||
|
public class SimpleCommand {
|
||||||
|
private CommandDispatcher<Object> dispatcher;
|
||||||
|
private ParseResults<Object> parse;
|
||||||
|
|
||||||
|
@Setup
|
||||||
|
public void setup() {
|
||||||
|
dispatcher = new CommandDispatcher<>();
|
||||||
|
dispatcher.register(literal("command").executes(c -> 0));
|
||||||
|
parse = dispatcher.parse("command", new Object());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||||
|
public void execute() throws CommandSyntaxException {
|
||||||
|
dispatcher.execute(parse);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue