5
5
GraphQLSchema , Source , execute , parse )
6
6
7
7
8
- def test_big_list_of_ints (benchmark ):
9
- big_int_list = [x for x in range (5000 )]
8
+ # set global fixtures
9
+ 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 )]
12
+
13
+ ContainerType = GraphQLObjectType ('Container' ,
14
+ fields = {
15
+ 'x' : GraphQLField (GraphQLInt ),
16
+ 'y' : GraphQLField (GraphQLInt ),
17
+ 'z' : GraphQLField (GraphQLInt ),
18
+ 'o' : GraphQLField (GraphQLInt ),
19
+ })
20
+
21
+
22
+ def resolve_all_containers (root , args , context , info ):
23
+ return big_container_list
10
24
11
- def resolve_all_ints (root , args , context , info ):
12
- return big_int_list
13
25
26
+ def resolve_all_ints (root , args , context , info ):
27
+ return big_int_list
28
+
29
+
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 ):
14
50
Query = GraphQLObjectType ('Query' , fields = {
15
51
'allInts' : GraphQLField (
16
52
GraphQLList (GraphQLInt ),
@@ -20,43 +56,55 @@ def resolve_all_ints(root, args, context, info):
20
56
hello_schema = GraphQLSchema (Query )
21
57
source = Source ('{ allInts }' )
22
58
ast = parse (source )
23
- big_list_query = partial (execute , hello_schema , ast )
24
- result = benchmark (big_list_query )
25
- # result = big_list_query()
26
- assert not result .errors
27
- assert result .data == {'allInts' : big_int_list }
28
59
60
+ @benchmark
61
+ 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 )
29
77
30
78
31
- def test_big_list_of_ints_base (benchmark ):
32
- big_int_list = [x for x in range (5000 )]
79
+ def test_big_list_of_ints_base_serialize (benchmark ):
33
80
from ..executor import complete_leaf_value
34
- # def convert_item(i):
35
- # return i
36
81
37
- def convert_list ():
38
- r = []
82
+ @ benchmark
83
+ def serialize ():
39
84
for i in big_int_list :
40
- r .append (GraphQLInt .serialize (i ))
41
- return r
42
- benchmark (convert_list )
85
+ GraphQLInt .serialize (i )
43
86
44
87
45
- def test_big_list_of_containers_with_one_field (benchmark ):
46
- Container = namedtuple ('Container' , 'x y z o' )
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 )
47
98
48
- ContainerType = GraphQLObjectType ('Container' , fields = {
49
- 'x' : GraphQLField (GraphQLInt ),
50
- 'y' : GraphQLField (GraphQLInt ),
51
- 'z' : GraphQLField (GraphQLInt ),
52
- 'o' : GraphQLField (GraphQLInt ),
53
- })
54
99
55
- big_container_list = [Container (x = x , y = x , z = x , o = x ) for x in range (5000 )]
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 )
56
105
57
- def resolve_all_containers (root , args , context , info ):
58
- return big_container_list
59
106
107
+ def test_total_big_list_of_containers_with_one_field_partial (benchmark ):
60
108
Query = GraphQLObjectType ('Query' , fields = {
61
109
'allContainers' : GraphQLField (
62
110
GraphQLList (ContainerType ),
@@ -66,39 +114,55 @@ def resolve_all_containers(root, args, context, info):
66
114
hello_schema = GraphQLSchema (Query )
67
115
source = Source ('{ allContainers { x } }' )
68
116
ast = parse (source )
69
- big_list_query = partial (execute , hello_schema , ast )
70
- result = benchmark (big_list_query )
71
- # result = big_list_query()
72
- assert not result .errors
73
- assert result .data == {'allContainers' : [{'x' : c .x } for c in big_container_list ]}
74
117
118
+ @benchmark
119
+ def b ():
120
+ return partial (execute , hello_schema , ast )
75
121
76
- def test_big_list_of_containers_with_multiple_fields (benchmark ):
77
- Container = namedtuple ('Container' , 'x y z o' )
78
122
79
- ContainerType = GraphQLObjectType ('Container' , fields = {
80
- 'x' : GraphQLField (GraphQLInt ),
81
- 'y' : GraphQLField (GraphQLInt ),
82
- 'z' : GraphQLField (GraphQLInt ),
83
- 'o' : GraphQLField (GraphQLInt ),
84
- })
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 )
85
136
86
- big_container_list = [Container (x = x , y = x , z = x , o = x ) for x in range (5000 )]
87
-
88
- def resolve_all_containers (root , args , context , info ):
89
- return big_container_list
90
137
138
+ def test_total_big_list_of_containers_with_multiple_fields_partial (benchmark ):
91
139
Query = GraphQLObjectType ('Query' , fields = {
92
140
'allContainers' : GraphQLField (
93
141
GraphQLList (ContainerType ),
94
142
resolver = resolve_all_containers
95
143
)
96
144
})
145
+
97
146
hello_schema = GraphQLSchema (Query )
98
147
source = Source ('{ allContainers { x, y, z } }' )
99
148
ast = parse (source )
100
- big_list_query = partial (execute , hello_schema , ast )
101
- result = benchmark (big_list_query )
102
- # result = big_list_query()
103
- assert not result .errors
104
- assert result .data == {'allContainers' : [{'x' : c .x , 'y' : c .y , 'z' : c .z } for c in big_container_list ]}
149
+
150
+ @benchmark
151
+ 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 )
0 commit comments