Skip to content

Commit 403d61e

Browse files
committed
Improved basic benchmark
1 parent 656eb7d commit 403d61e

File tree

1 file changed

+17
-98
lines changed

1 file changed

+17
-98
lines changed

graphql/execution/tests/test_benchmark.py

Lines changed: 17 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33

44
from graphql import (GraphQLField, GraphQLInt, GraphQLList, GraphQLObjectType,
55
GraphQLSchema, Source, execute, parse)
6+
# from graphql.execution import executor
67

8+
# executor.use_experimental_executor = True
79

10+
SIZE = 10000
811
# set global fixtures
912
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)]
1215

1316
ContainerType = GraphQLObjectType('Container',
1417
fields={
@@ -27,142 +30,58 @@ def resolve_all_ints(root, args, context, info):
2730
return big_int_list
2831

2932

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):
5034
Query = GraphQLObjectType('Query', fields={
5135
'allInts': GraphQLField(
5236
GraphQLList(GraphQLInt),
5337
resolver=resolve_all_ints
5438
)
5539
})
56-
hello_schema = GraphQLSchema(Query)
40+
schema = GraphQLSchema(Query)
5741
source = Source('{ allInts }')
5842
ast = parse(source)
5943

6044
@benchmark
6145
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)
7747

7848

79-
def test_big_list_of_ints_base_serialize(benchmark):
49+
def test_big_list_of_ints_serialize(benchmark):
8050
from ..executor import complete_leaf_value
8151

8252
@benchmark
8353
def serialize():
84-
for i in big_int_list:
85-
GraphQLInt.serialize(i)
54+
map(GraphQLInt.serialize, big_int_list)
8655

8756

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):
10858
Query = GraphQLObjectType('Query', fields={
10959
'allContainers': GraphQLField(
11060
GraphQLList(ContainerType),
11161
resolver=resolve_all_containers
11262
)
11363
})
114-
hello_schema = GraphQLSchema(Query)
64+
schema = GraphQLSchema(Query)
11565
source = Source('{ allContainers { x } }')
11666
ast = parse(source)
11767

11868
@benchmark
11969
def b():
120-
return partial(execute, hello_schema, ast)
70+
return execute(schema, ast)
12171

12272

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):
13974
Query = GraphQLObjectType('Query', fields={
14075
'allContainers': GraphQLField(
14176
GraphQLList(ContainerType),
14277
resolver=resolve_all_containers
14378
)
14479
})
14580

146-
hello_schema = GraphQLSchema(Query)
147-
source = Source('{ allContainers { x, y, z } }')
81+
schema = GraphQLSchema(Query)
82+
source = Source('{ allContainers { x, y } }')
14883
ast = parse(source)
14984

15085
@benchmark
15186
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

Comments
 (0)