forked from graphql-java/graphql-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSchemaBenchMark.java
More file actions
69 lines (61 loc) · 2.31 KB
/
SchemaBenchMark.java
File metadata and controls
69 lines (61 loc) · 2.31 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
package benchmark;
import com.google.common.io.Files;
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.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 java.io.File;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.concurrent.TimeUnit;
/**
* This benchmarks schema creation
* <p>
* See https://github.com/openjdk/jmh/tree/master/jmh-samples/src/main/java/org/openjdk/jmh/samples/ for more samples
* on what you can do with JMH
* <p>
* You MUST have the JMH plugin for IDEA in place for this to work : https://github.com/artyushov/idea-jmh-plugin
* <p>
* Install it and then just hit "Run" on a certain benchmark method
*/
@Warmup(iterations = 2, time = 5, batchSize = 3)
@Measurement(iterations = 3, time = 10, batchSize = 4)
public class SchemaBenchMark {
static String largeSDL = BenchmarkUtils.loadResource("large-schema-3.graphqls");
@Benchmark
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MINUTES)
public void benchMarkLargeSchemaCreate(Blackhole blackhole) {
blackhole.consume(createSchema(largeSDL));
}
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public void benchMarkLargeSchemaCreateAvgTime(Blackhole blackhole) {
blackhole.consume(createSchema(largeSDL));
}
private static GraphQLSchema createSchema(String sdl) {
TypeDefinitionRegistry registry = new SchemaParser().parse(sdl);
return new SchemaGenerator().makeExecutableSchema(registry, RuntimeWiring.MOCKED_WIRING);
}
@SuppressWarnings("InfiniteLoopStatement")
/// make this a main method if you want to run it in JProfiler etc..
public static void mainXXX(String[] args) {
int i = 0;
while (true) {
createSchema(largeSDL);
i++;
if (i % 100 == 0) {
System.out.printf("%d\n", i);
}
}
}
}