55 GraphQLSchema , Source , execute , parse )
66
77
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
1024
11- def resolve_all_ints (root , args , context , info ):
12- return big_int_list
1325
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 ):
1450 Query = GraphQLObjectType ('Query' , fields = {
1551 'allInts' : GraphQLField (
1652 GraphQLList (GraphQLInt ),
@@ -20,43 +56,55 @@ def resolve_all_ints(root, args, context, info):
2056 hello_schema = GraphQLSchema (Query )
2157 source = Source ('{ allInts }' )
2258 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 }
2859
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 )
2977
3078
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 ):
3380 from ..executor import complete_leaf_value
34- # def convert_item(i):
35- # return i
3681
37- def convert_list ():
38- r = []
82+ @ benchmark
83+ def serialize ():
3984 for i in big_int_list :
40- r .append (GraphQLInt .serialize (i ))
41- return r
42- benchmark (convert_list )
85+ GraphQLInt .serialize (i )
4386
4487
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 )
4798
48- ContainerType = GraphQLObjectType ('Container' , fields = {
49- 'x' : GraphQLField (GraphQLInt ),
50- 'y' : GraphQLField (GraphQLInt ),
51- 'z' : GraphQLField (GraphQLInt ),
52- 'o' : GraphQLField (GraphQLInt ),
53- })
5499
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 )
56105
57- def resolve_all_containers (root , args , context , info ):
58- return big_container_list
59106
107+ def test_total_big_list_of_containers_with_one_field_partial (benchmark ):
60108 Query = GraphQLObjectType ('Query' , fields = {
61109 'allContainers' : GraphQLField (
62110 GraphQLList (ContainerType ),
@@ -66,39 +114,55 @@ def resolve_all_containers(root, args, context, info):
66114 hello_schema = GraphQLSchema (Query )
67115 source = Source ('{ allContainers { x } }' )
68116 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 ]}
74117
118+ @benchmark
119+ def b ():
120+ return partial (execute , hello_schema , ast )
75121
76- def test_big_list_of_containers_with_multiple_fields (benchmark ):
77- Container = namedtuple ('Container' , 'x y z o' )
78122
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 )
85136
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
90137
138+ def test_total_big_list_of_containers_with_multiple_fields_partial (benchmark ):
91139 Query = GraphQLObjectType ('Query' , fields = {
92140 'allContainers' : GraphQLField (
93141 GraphQLList (ContainerType ),
94142 resolver = resolve_all_containers
95143 )
96144 })
145+
97146 hello_schema = GraphQLSchema (Query )
98147 source = Source ('{ allContainers { x, y, z } }' )
99148 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