forked from graphql-java/graphql-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateExtendedSchemaBenchmark.java
More file actions
121 lines (104 loc) · 3.79 KB
/
Copy pathCreateExtendedSchemaBenchmark.java
File metadata and controls
121 lines (104 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package benchmark;
import graphql.schema.GraphQLSchema;
import graphql.schema.idl.RuntimeWiring;
import graphql.schema.idl.SchemaGenerator;
import graphql.schema.idl.SchemaParser;
import graphql.schema.idl.TypeDefinitionRegistry;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.Blackhole;
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;
import static benchmark.BenchmarkUtils.runInToolingForSomeTimeThenExit;
/**
* This JMH
*/
@Warmup(iterations = 2, time = 5)
@Measurement(iterations = 3)
@Fork(2)
public class CreateExtendedSchemaBenchmark {
private static final String SDL = mkSDL();
@Benchmark
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MINUTES)
public void benchmarkLargeSchemaCreate(Blackhole blackhole) {
blackhole.consume(createSchema(SDL));
}
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public void benchmarkLargeSchemaCreateAvgTime(Blackhole blackhole) {
blackhole.consume(createSchema(SDL));
}
private static GraphQLSchema createSchema(String sdl) {
TypeDefinitionRegistry registry = new SchemaParser().parse(sdl);
return new SchemaGenerator().makeExecutableSchema(registry, RuntimeWiring.MOCKED_WIRING);
}
/* something like
type Query { q : String } interface I { f : String }
interface I1 implements I {
f : String
f1 : String
}
type O1_1 implements I1 & I {
f : String
f1 : String
}
type O1_2 implements I1 & I {
f : String
f1 : String
}
*/
private static String mkSDL() {
int numTypes = 10000;
int numExtends = 10;
StringBuilder sb = new StringBuilder();
sb.append("type Query { q : String } interface I { f : String } interface X { x : String }\n");
for (int i = 0; i < numTypes; i++) {
sb.append("interface I").append(i).append(" implements I { \n")
.append("\tf : String \n")
.append("\tf").append(i).append(" : String \n").append("}\n");
sb.append("type O").append(i).append(" implements I").append(i).append(" & I { \n")
.append("\tf : String \n")
.append("\tf").append(i).append(" : String \n")
.append("}\n");
sb.append("extend type O").append(i).append(" implements X").append(" { \n")
.append("\tx : String \n")
.append("}\n");
for (int j = 0; j < numExtends; j++) {
sb.append("extend type O").append(i).append(" { \n")
.append("\textendedF").append(j).append(" : String \n")
.append("}\n");
}
}
return sb.toString();
}
public static void main(String[] args) throws RunnerException {
try {
runAtStartup();
} catch (Throwable e) {
throw new RuntimeException(e);
}
Options opt = new OptionsBuilder()
.include("benchmark.CreateExtendedSchemaBenchmark")
.build();
new Runner(opt).run();
}
private static void runAtStartup() {
runInToolingForSomeTimeThenExit(
() -> {
},
() -> createSchema(SDL),
() -> {
}
);
}
}