Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 34 additions & 10 deletions src/jmh/java/benchmark/IntrospectionBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,58 @@
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

import java.util.concurrent.TimeUnit;

@State(Scope.Benchmark)
@Warmup(iterations = 2, time = 5)
@Measurement(iterations = 3)
@Fork(2)
public class IntrospectionBenchmark {

@Param({
"large-schema-2.graphqls",
"large-schema-3.graphqls",
"large-schema-4.graphqls",
"large-schema-5.graphqls",
"large-schema-federated-1.graphqls"
})
String schemaFile;

private GraphQL graphQL;

@Setup(Level.Trial)
public void setup() {
String schema = loadSchema(schemaFile);
GraphQLSchema graphQLSchema = SchemaGenerator.createdMockedSchema(schema);
graphQL = GraphQL.newGraphQL(graphQLSchema).build();
}

private static String loadSchema(String schemaFile) {
if (schemaFile.equals("large-schema-5.graphqls")) {
// This schema is split across two files due to its size (11.3 MB)
return BenchmarkUtils.loadResource("large-schema-5.graphqls.part1")
+ BenchmarkUtils.loadResource("large-schema-5.graphqls.part2");
}
return BenchmarkUtils.loadResource(schemaFile);
}

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public ExecutionResult benchMarkIntrospectionAvgTime() {
return graphQL.execute(IntrospectionQuery.INTROSPECTION_QUERY);
}
Expand All @@ -36,16 +70,6 @@ public ExecutionResult benchMarkIntrospectionThroughput() {
return graphQL.execute(IntrospectionQuery.INTROSPECTION_QUERY);
}

private final GraphQL graphQL;


public IntrospectionBenchmark() {
String largeSchema = BenchmarkUtils.loadResource("large-schema-4.graphqls");
GraphQLSchema graphQLSchema = SchemaGenerator.createdMockedSchema(largeSchema);
graphQL = GraphQL.newGraphQL(graphQLSchema)
.build();
}

public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include("benchmark.IntrospectionBenchmark")
Expand Down
Loading