5
5
GraphQLSchema , Source , execute , parse )
6
6
7
7
8
+ SIZE = 10000
9
+
8
10
def test_big_list_of_ints (benchmark ):
9
- big_int_list = [x for x in range (5000 )]
11
+ big_int_list = [x for x in range (SIZE )]
10
12
11
13
def resolve_all_ints (root , args , context , info ):
12
14
return big_int_list
@@ -28,8 +30,8 @@ def resolve_all_ints(root, args, context, info):
28
30
29
31
30
32
31
- def test_big_list_of_ints_base (benchmark ):
32
- big_int_list = [x for x in range (5000 )]
33
+ def test_big_list_of_ints_only_serialize (benchmark ):
34
+ big_int_list = [x for x in range (SIZE )]
33
35
from ..executor import complete_leaf_value
34
36
# def convert_item(i):
35
37
# return i
@@ -42,6 +44,32 @@ def convert_list():
42
44
benchmark (convert_list )
43
45
44
46
47
+ def test_big_list_of_objecttypes_with_one_int_field (benchmark ):
48
+ ContainerType = GraphQLObjectType ('Container' , fields = {
49
+ 'x' : GraphQLField (GraphQLInt , resolver = lambda root , args , context , info : root ),
50
+ })
51
+
52
+ big_container_list = [x for x in range (SIZE )]
53
+
54
+ def resolve_all_containers (root , args , context , info ):
55
+ return big_container_list
56
+
57
+ Query = GraphQLObjectType ('Query' , fields = {
58
+ 'allContainers' : GraphQLField (
59
+ GraphQLList (ContainerType ),
60
+ resolver = resolve_all_containers
61
+ )
62
+ })
63
+ hello_schema = GraphQLSchema (Query )
64
+ source = Source ('{ allContainers { x } }' )
65
+ ast = parse (source )
66
+ big_list_query = partial (execute , hello_schema , ast )
67
+ result = benchmark (big_list_query )
68
+ # result = big_list_query()
69
+ assert not result .errors
70
+ assert result .data == {'allContainers' : [{'x' : x } for x in big_container_list ]}
71
+
72
+
45
73
def test_big_list_of_containers_with_one_field (benchmark ):
46
74
Container = namedtuple ('Container' , 'x y z o' )
47
75
@@ -52,7 +80,7 @@ def test_big_list_of_containers_with_one_field(benchmark):
52
80
'o' : GraphQLField (GraphQLInt ),
53
81
})
54
82
55
- big_container_list = [Container (x = x , y = x , z = x , o = x ) for x in range (5000 )]
83
+ big_container_list = [Container (x = x , y = x , z = x , o = x ) for x in range (SIZE )]
56
84
57
85
def resolve_all_containers (root , args , context , info ):
58
86
return big_container_list
@@ -83,7 +111,7 @@ def test_big_list_of_containers_with_multiple_fields(benchmark):
83
111
'o' : GraphQLField (GraphQLInt ),
84
112
})
85
113
86
- big_container_list = [Container (x = x , y = x , z = x , o = x ) for x in range (5000 )]
114
+ big_container_list = [Container (x = x , y = x , z = x , o = x ) for x in range (SIZE )]
87
115
88
116
def resolve_all_containers (root , args , context , info ):
89
117
return big_container_list
0 commit comments