Repository navigation
Expand file tree
/
Copy pathBuildSchemaBenchmark.java
More file actions
54 lines (46 loc) · 1.82 KB
/
Copy pathBuildSchemaBenchmark.java
File metadata and controls
54 lines (46 loc) · 1.82 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
package benchmark;
import graphql.schema.idl.FastSchemaGenerator;
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.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.Blackhole;
import java.util.concurrent.TimeUnit;
@Warmup(iterations = 2, time = 5)
@Measurement(iterations = 3)
@Fork(2)
@State(Scope.Benchmark)
public class BuildSchemaBenchmark {
static String largeSDL = BenchmarkUtils.loadResource("large-schema-4.graphqls");
private TypeDefinitionRegistry registry;
@Setup
public void setup() {
// Parse SDL once before benchmarks run
registry = new SchemaParser().parse(largeSDL);
}
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public void benchmarkBuildSchemaAvgTime(Blackhole blackhole) {
blackhole.consume(new SchemaGenerator().makeExecutableSchema(registry, RuntimeWiring.MOCKED_WIRING));
}
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public void benchmarkBuildSchemaAvgTimeFast(Blackhole blackhole) {
blackhole.consume(new FastSchemaGenerator().makeExecutableSchema(
SchemaGenerator.Options.defaultOptions().withValidation(false),
registry,
RuntimeWiring.MOCKED_WIRING));
}
}