forked from graphql-java/graphql-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAstPrinterBenchmark.java
More file actions
236 lines (230 loc) · 6.93 KB
/
AstPrinterBenchmark.java
File metadata and controls
236 lines (230 loc) · 6.93 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
package benchmark;
import graphql.language.AstPrinter;
import graphql.language.Document;
import graphql.parser.Parser;
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.util.concurrent.TimeUnit;
/**
* 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 AstPrinterBenchmark {
/**
* Note: this query is a redacted version of a real query
*/
private static final Document document = Parser.parse("query fang($slip: dinner!) {\n" +
" instinctive(thin: $slip) {\n" +
" annoy {\n" +
" ...account\n" +
" }\n" +
" massive {\n" +
" ...cellar\n" +
" }\n" +
" used {\n" +
" ...rinse\n" +
" }\n" +
" distinct(sedate: [disarm]) {\n" +
" ...lamp\n" +
" }\n" +
" venomous {\n" +
" uninterested\n" +
" }\n" +
" correct {\n" +
" ...plane\n" +
" }\n" +
" drown\n" +
" talk {\n" +
" house\n" +
" womanly\n" +
" royal {\n" +
" ...snore\n" +
" }\n" +
" gray\n" +
" normal\n" +
" proud\n" +
" crate\n" +
" billowy {\n" +
" frogs\n" +
" abstracted\n" +
" market\n" +
" corn\n" +
" }\n" +
" tip {\n" +
" ...public\n" +
" }\n" +
" stick {\n" +
" ...precious\n" +
" }\n" +
" null {\n" +
" ...precious\n" +
" }\n" +
" }\n" +
" }\n" +
"}\n" +
"\n" +
"fragment account on bath {\n" +
" purpose\n" +
" festive\n" +
" ruddy\n" +
"}\n" +
"\n" +
"fragment cellar on thunder {\n" +
" debonair\n" +
" immense\n" +
" object\n" +
" moon\n" +
" icy {\n" +
" furniture\n" +
" historical\n" +
" team\n" +
" root\n" +
" }\n" +
"}\n" +
"\n" +
"fragment rinse on song {\n" +
" reply {\n" +
" sticks\n" +
" unbecoming\n" +
" }\n" +
" love {\n" +
" annoying\n" +
" sign\n" +
" }\n" +
"}\n" +
"\n" +
"fragment lamp on heartbreaking {\n" +
" innocent\n" +
" decorate\n" +
" pancake\n" +
" arithmetic\n" +
" grey\n" +
" brass\n" +
" pocket\n" +
"}\n" +
"\n" +
"fragment snore on tired {\n" +
" share\n" +
" baseball\n" +
" suspend\n" +
"}\n" +
"\n" +
"fragment settle on incompetent {\n" +
" name\n" +
" juggle\n" +
" depressed\n" +
"}\n" +
"\n" +
"fragment few on puffy {\n" +
" ticket\n" +
" puny\n" +
" copy\n" +
" coast\n" +
"}\n" +
"\n" +
"fragment plane on seat {\n" +
" ice\n" +
" mug\n" +
" wobble\n" +
" clear\n" +
" toys {\n" +
" ...few\n" +
" }\n" +
"}\n" +
"\n" +
"fragment public on basin {\n" +
" different\n" +
" fang\n" +
" slip\n" +
" dinner\n" +
" instinctive\n" +
" thin {\n" +
" annoy {\n" +
" account\n" +
" massive\n" +
" cellar\n" +
" used\n" +
" rinse {\n" +
" distinct\n" +
" }\n" +
" sedate {\n" +
" disarm\n" +
" }\n" +
" lamp {\n" +
" venomous\n" +
" }\n" +
" }\n" +
" uninterested {\n" +
" ...settle\n" +
" }\n" +
" }\n" +
"}\n" +
"\n" +
"fragment precious on drown {\n" +
" talk\n" +
" house\n" +
" womanly\n" +
" royal {\n" +
" snore {\n" +
" gray\n" +
" }\n" +
" normal {\n" +
" proud\n" +
" crate\n" +
" billowy\n" +
" frogs\n" +
" abstracted {\n" +
" ...snore\n" +
" }\n" +
" corn {\n" +
" tip\n" +
" public\n" +
" }\n" +
" stick {\n" +
" ...settle\n" +
" }\n" +
" null {\n" +
" ...few\n" +
" }\n" +
" marry\n" +
" bath {\n" +
" purpose\n" +
" festive\n" +
" }\n" +
" ruddy\n" +
" help\n" +
" thunder\n" +
" debonair {\n" +
" immense\n" +
" }\n" +
" object\n" +
" }\n" +
" }\n" +
"}");
@Benchmark
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.SECONDS)
public void benchMarkAstPrinterThroughput(Blackhole blackhole) {
printAst(blackhole);
}
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public void benchMarkAstPrinterAvgTime(Blackhole blackhole) {
printAst(blackhole);
}
public static void printAst(Blackhole blackhole) {
blackhole.consume(AstPrinter.printAst(document));
}
}