88import org .openjdk .jmh .annotations .Benchmark ;
99import org .openjdk .jmh .annotations .BenchmarkMode ;
1010import org .openjdk .jmh .annotations .Fork ;
11+ import org .openjdk .jmh .annotations .Level ;
1112import org .openjdk .jmh .annotations .Measurement ;
1213import org .openjdk .jmh .annotations .Mode ;
14+ import org .openjdk .jmh .annotations .OutputTimeUnit ;
15+ import org .openjdk .jmh .annotations .Param ;
1316import org .openjdk .jmh .annotations .Scope ;
17+ import org .openjdk .jmh .annotations .Setup ;
1418import org .openjdk .jmh .annotations .State ;
1519import org .openjdk .jmh .annotations .Warmup ;
1620import org .openjdk .jmh .runner .Runner ;
1721import org .openjdk .jmh .runner .RunnerException ;
1822import org .openjdk .jmh .runner .options .Options ;
1923import org .openjdk .jmh .runner .options .OptionsBuilder ;
2024
25+ import java .util .concurrent .TimeUnit ;
26+
2127@ State (Scope .Benchmark )
2228@ Warmup (iterations = 2 , time = 5 )
2329@ Measurement (iterations = 3 )
2430@ Fork (2 )
2531public class IntrospectionBenchmark {
2632
33+ @ Param ({
34+ "large-schema-2.graphqls" ,
35+ "large-schema-3.graphqls" ,
36+ "large-schema-4.graphqls" ,
37+ "large-schema-5.graphqls" ,
38+ "large-schema-federated-1.graphqls"
39+ })
40+ String schemaFile ;
41+
42+ private GraphQL graphQL ;
43+
44+ @ Setup (Level .Trial )
45+ public void setup () {
46+ String schema = loadSchema (schemaFile );
47+ GraphQLSchema graphQLSchema = SchemaGenerator .createdMockedSchema (schema );
48+ graphQL = GraphQL .newGraphQL (graphQLSchema ).build ();
49+ }
50+
51+ private static String loadSchema (String schemaFile ) {
52+ if (schemaFile .equals ("large-schema-5.graphqls" )) {
53+ // This schema is split across two files due to its size (11.3 MB)
54+ return BenchmarkUtils .loadResource ("large-schema-5.graphqls.part1" )
55+ + BenchmarkUtils .loadResource ("large-schema-5.graphqls.part2" );
56+ }
57+ return BenchmarkUtils .loadResource (schemaFile );
58+ }
59+
2760 @ Benchmark
2861 @ BenchmarkMode (Mode .AverageTime )
62+ @ OutputTimeUnit (TimeUnit .MILLISECONDS )
2963 public ExecutionResult benchMarkIntrospectionAvgTime () {
3064 return graphQL .execute (IntrospectionQuery .INTROSPECTION_QUERY );
3165 }
@@ -36,16 +70,6 @@ public ExecutionResult benchMarkIntrospectionThroughput() {
3670 return graphQL .execute (IntrospectionQuery .INTROSPECTION_QUERY );
3771 }
3872
39- private final GraphQL graphQL ;
40-
41-
42- public IntrospectionBenchmark () {
43- String largeSchema = BenchmarkUtils .loadResource ("large-schema-4.graphqls" );
44- GraphQLSchema graphQLSchema = SchemaGenerator .createdMockedSchema (largeSchema );
45- graphQL = GraphQL .newGraphQL (graphQLSchema )
46- .build ();
47- }
48-
4973 public static void main (String [] args ) throws RunnerException {
5074 Options opt = new OptionsBuilder ()
5175 .include ("benchmark.IntrospectionBenchmark" )
0 commit comments