-
Notifications
You must be signed in to change notification settings - Fork 839
/
graphql_bench_test.go
124 lines (99 loc) · 2.35 KB
/
graphql_bench_test.go
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
package graphql_test
import (
"testing"
"github.com/graphql-go/graphql"
"github.com/graphql-go/graphql/benchutil"
)
type B struct {
Query string
Schema graphql.Schema
}
func benchGraphql(bench B, p graphql.Params, t testing.TB) {
result := graphql.Do(p)
if len(result.Errors) > 0 {
t.Fatalf("wrong result, unexpected errors: %v", result.Errors)
}
}
// Benchmark a reasonably large list of small items.
func BenchmarkListQuery_1(b *testing.B) {
nItemsListQueryBenchmark(1)(b)
}
func BenchmarkListQuery_100(b *testing.B) {
nItemsListQueryBenchmark(100)(b)
}
func BenchmarkListQuery_1K(b *testing.B) {
nItemsListQueryBenchmark(1000)(b)
}
func BenchmarkListQuery_10K(b *testing.B) {
nItemsListQueryBenchmark(10 * 1000)(b)
}
func BenchmarkListQuery_100K(b *testing.B) {
nItemsListQueryBenchmark(100 * 1000)(b)
}
func nItemsListQueryBenchmark(x int) func(b *testing.B) {
return func(b *testing.B) {
schema := benchutil.ListSchemaWithXItems(x)
bench := B{
Query: `
query {
colors {
hex
r
g
b
}
}
`,
Schema: schema,
}
for i := 0; i < b.N; i++ {
params := graphql.Params{
Schema: schema,
RequestString: bench.Query,
}
benchGraphql(bench, params, b)
}
}
}
func BenchmarkWideQuery_1_1(b *testing.B) {
nFieldsyItemsQueryBenchmark(1, 1)(b)
}
func BenchmarkWideQuery_10_1(b *testing.B) {
nFieldsyItemsQueryBenchmark(10, 1)(b)
}
func BenchmarkWideQuery_100_1(b *testing.B) {
nFieldsyItemsQueryBenchmark(100, 1)(b)
}
func BenchmarkWideQuery_1K_1(b *testing.B) {
nFieldsyItemsQueryBenchmark(1000, 1)(b)
}
func BenchmarkWideQuery_1_10(b *testing.B) {
nFieldsyItemsQueryBenchmark(1, 10)(b)
}
func BenchmarkWideQuery_10_10(b *testing.B) {
nFieldsyItemsQueryBenchmark(10, 10)(b)
}
func BenchmarkWideQuery_100_10(b *testing.B) {
nFieldsyItemsQueryBenchmark(100, 10)(b)
}
func BenchmarkWideQuery_1K_10(b *testing.B) {
nFieldsyItemsQueryBenchmark(1000, 10)(b)
}
func nFieldsyItemsQueryBenchmark(x int, y int) func(b *testing.B) {
return func(b *testing.B) {
schema := benchutil.WideSchemaWithXFieldsAndYItems(x, y)
query := benchutil.WideSchemaQuery(x)
bench := B{
Query: query,
Schema: schema,
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
params := graphql.Params{
Schema: schema,
RequestString: bench.Query,
}
benchGraphql(bench, params, b)
}
}
}