3
3
4
4
from graphql import (GraphQLField , GraphQLInt , GraphQLList , GraphQLObjectType ,
5
5
GraphQLSchema , Source , execute , parse )
6
+ # from graphql.execution import executor
6
7
8
+ # executor.use_experimental_executor = True
7
9
10
+ SIZE = 10000
8
11
# set global fixtures
9
12
Container = namedtuple ('Container' , 'x y z o' )
10
- big_int_list = [x for x in range (5000 )]
11
- big_container_list = [Container (x = x , y = x , z = x , o = x ) for x in range (5000 )]
13
+ big_int_list = [x for x in range (SIZE )]
14
+ big_container_list = [Container (x = x , y = x , z = x , o = x ) for x in range (SIZE )]
12
15
13
16
ContainerType = GraphQLObjectType ('Container' ,
14
17
fields = {
@@ -27,142 +30,58 @@ def resolve_all_ints(root, args, context, info):
27
30
return big_int_list
28
31
29
32
30
- def test_big_list_of_ints_to_graphql_schema (benchmark ):
31
- @benchmark
32
- def schema ():
33
- Query = GraphQLObjectType ('Query' , fields = {
34
- 'allInts' : GraphQLField (
35
- GraphQLList (GraphQLInt ),
36
- resolver = resolve_all_ints
37
- )
38
- })
39
- return GraphQLSchema (Query )
40
-
41
-
42
- def test_big_list_of_ints_to_graphql_ast (benchmark ):
43
- @benchmark
44
- def ast ():
45
- source = Source ('{ allInts }' )
46
- return parse (source )
47
-
48
-
49
- def test_big_list_of_ints_to_graphql_partial (benchmark ):
33
+ def test_big_list_of_ints (benchmark ):
50
34
Query = GraphQLObjectType ('Query' , fields = {
51
35
'allInts' : GraphQLField (
52
36
GraphQLList (GraphQLInt ),
53
37
resolver = resolve_all_ints
54
38
)
55
39
})
56
- hello_schema = GraphQLSchema (Query )
40
+ schema = GraphQLSchema (Query )
57
41
source = Source ('{ allInts }' )
58
42
ast = parse (source )
59
43
60
44
@benchmark
61
45
def b ():
62
- return partial (execute , hello_schema , ast )
63
-
64
- def test_big_list_of_ints_to_graphql_total (benchmark ):
65
- @benchmark
66
- def total ():
67
- Query = GraphQLObjectType ('Query' , fields = {
68
- 'allInts' : GraphQLField (
69
- GraphQLList (GraphQLInt ),
70
- resolver = resolve_all_ints
71
- )
72
- })
73
- hello_schema = GraphQLSchema (Query )
74
- source = Source ('{ allInts }' )
75
- ast = parse (source )
76
- return partial (execute , hello_schema , ast )
46
+ return execute (schema , ast )
77
47
78
48
79
- def test_big_list_of_ints_base_serialize (benchmark ):
49
+ def test_big_list_of_ints_serialize (benchmark ):
80
50
from ..executor import complete_leaf_value
81
51
82
52
@benchmark
83
53
def serialize ():
84
- for i in big_int_list :
85
- GraphQLInt .serialize (i )
54
+ map (GraphQLInt .serialize , big_int_list )
86
55
87
56
88
- def test_total_big_list_of_containers_with_one_field_schema (benchmark ):
89
- @benchmark
90
- def schema ():
91
- Query = GraphQLObjectType ('Query' , fields = {
92
- 'allContainers' : GraphQLField (
93
- GraphQLList (ContainerType ),
94
- resolver = resolve_all_containers
95
- )
96
- })
97
- return GraphQLSchema (Query )
98
-
99
-
100
- def test_total_big_list_of_containers_with_one_field_parse (benchmark ):
101
- @benchmark
102
- def ast ():
103
- source = Source ('{ allContainers { x } }' )
104
- ast = parse (source )
105
-
106
-
107
- def test_total_big_list_of_containers_with_one_field_partial (benchmark ):
57
+ def test_big_list_objecttypes_with_one_int_field (benchmark ):
108
58
Query = GraphQLObjectType ('Query' , fields = {
109
59
'allContainers' : GraphQLField (
110
60
GraphQLList (ContainerType ),
111
61
resolver = resolve_all_containers
112
62
)
113
63
})
114
- hello_schema = GraphQLSchema (Query )
64
+ schema = GraphQLSchema (Query )
115
65
source = Source ('{ allContainers { x } }' )
116
66
ast = parse (source )
117
67
118
68
@benchmark
119
69
def b ():
120
- return partial ( execute , hello_schema , ast )
70
+ return execute ( schema , ast )
121
71
122
72
123
- def test_total_big_list_of_containers_with_one_field_total (benchmark ):
124
- @benchmark
125
- def total ():
126
- Query = GraphQLObjectType ('Query' , fields = {
127
- 'allContainers' : GraphQLField (
128
- GraphQLList (ContainerType ),
129
- resolver = resolve_all_containers
130
- )
131
- })
132
- hello_schema = GraphQLSchema (Query )
133
- source = Source ('{ allContainers { x } }' )
134
- ast = parse (source )
135
- result = partial (execute , hello_schema , ast )
136
-
137
-
138
- def test_total_big_list_of_containers_with_multiple_fields_partial (benchmark ):
73
+ def test_big_list_objecttypes_with_two_int_fields (benchmark ):
139
74
Query = GraphQLObjectType ('Query' , fields = {
140
75
'allContainers' : GraphQLField (
141
76
GraphQLList (ContainerType ),
142
77
resolver = resolve_all_containers
143
78
)
144
79
})
145
80
146
- hello_schema = GraphQLSchema (Query )
147
- source = Source ('{ allContainers { x, y, z } }' )
81
+ schema = GraphQLSchema (Query )
82
+ source = Source ('{ allContainers { x, y } }' )
148
83
ast = parse (source )
149
84
150
85
@benchmark
151
86
def b ():
152
- return partial (execute , hello_schema , ast )
153
-
154
-
155
- def test_total_big_list_of_containers_with_multiple_fields (benchmark ):
156
- @benchmark
157
- def total ():
158
- Query = GraphQLObjectType ('Query' , fields = {
159
- 'allContainers' : GraphQLField (
160
- GraphQLList (ContainerType ),
161
- resolver = resolve_all_containers
162
- )
163
- })
164
-
165
- hello_schema = GraphQLSchema (Query )
166
- source = Source ('{ allContainers { x, y, z } }' )
167
- ast = parse (source )
168
- result = partial (execute , hello_schema , ast )
87
+ return execute (schema , ast )
0 commit comments