|
| 1 | +package benchmark; |
| 2 | + |
| 3 | +import graphql.execution.CoercedVariables; |
| 4 | +import graphql.language.Document; |
| 5 | +import graphql.normalized.ExecutableNormalizedOperation; |
| 6 | +import graphql.normalized.ExecutableNormalizedOperationFactory; |
| 7 | +import graphql.parser.Parser; |
| 8 | +import graphql.schema.GraphQLSchema; |
| 9 | +import graphql.schema.idl.SchemaGenerator; |
| 10 | +import org.openjdk.jmh.annotations.Benchmark; |
| 11 | +import org.openjdk.jmh.annotations.BenchmarkMode; |
| 12 | +import org.openjdk.jmh.annotations.Fork; |
| 13 | +import org.openjdk.jmh.annotations.Measurement; |
| 14 | +import org.openjdk.jmh.annotations.Mode; |
| 15 | +import org.openjdk.jmh.annotations.OutputTimeUnit; |
| 16 | +import org.openjdk.jmh.annotations.Scope; |
| 17 | +import org.openjdk.jmh.annotations.Setup; |
| 18 | +import org.openjdk.jmh.annotations.State; |
| 19 | +import org.openjdk.jmh.annotations.Warmup; |
| 20 | + |
| 21 | +import java.util.concurrent.TimeUnit; |
| 22 | + |
| 23 | +@State(Scope.Benchmark) |
| 24 | +@Warmup(iterations = 2, time = 5) |
| 25 | +@Measurement(iterations = 3) |
| 26 | +@Fork(3) |
| 27 | +public class ENFBenchmark2 { |
| 28 | + |
| 29 | + @State(Scope.Benchmark) |
| 30 | + public static class MyState { |
| 31 | + |
| 32 | + GraphQLSchema schema; |
| 33 | + Document document; |
| 34 | + |
| 35 | + @Setup |
| 36 | + public void setup() { |
| 37 | + try { |
| 38 | + String schemaString = BenchmarkUtils.loadResource("large-schema-2.graphqls"); |
| 39 | + schema = SchemaGenerator.createdMockedSchema(schemaString); |
| 40 | + |
| 41 | + String query = BenchmarkUtils.loadResource("large-schema-2-query.graphql"); |
| 42 | + document = Parser.parse(query); |
| 43 | + } catch (Exception e) { |
| 44 | + throw new RuntimeException(e); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + } |
| 49 | + |
| 50 | + @Benchmark |
| 51 | + @BenchmarkMode(Mode.AverageTime) |
| 52 | + @OutputTimeUnit(TimeUnit.MILLISECONDS) |
| 53 | + public ExecutableNormalizedOperation benchMarkAvgTime(MyState myState) { |
| 54 | + ExecutableNormalizedOperation executableNormalizedOperation = ExecutableNormalizedOperationFactory.createExecutableNormalizedOperation(myState.schema, myState.document, null, CoercedVariables.emptyVariables()); |
| 55 | +// System.out.println("fields size:" + normalizedQuery.getFieldToNormalizedField().size()); |
| 56 | + return executableNormalizedOperation; |
| 57 | + } |
| 58 | + |
| 59 | +} |
0 commit comments