Skip to content

Commit 14e4ee6

Browse files
committed
Make all benchmarks cases similar so is easier to compare
1 parent 07458cd commit 14e4ee6

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

graphql/execution/querybuilder/tests/test_querybuilder.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def test_fragment_operation_mutation():
106106
execute_serially=True
107107
)
108108

109+
109110
def test_query_builder_operation():
110111
Node = GraphQLObjectType('Node', fields={'id': GraphQLField(GraphQLInt)})
111112
Query = GraphQLObjectType('Query', fields={'nodes': GraphQLField(GraphQLList(Node))})
@@ -144,3 +145,24 @@ def test_query_builder_operation():
144145
)
145146
}
146147
)
148+
149+
150+
def test_query_builder_execution():
151+
Node = GraphQLObjectType('Node', fields={'id': GraphQLField(GraphQLInt, resolver=lambda obj, **__: obj)})
152+
Query = GraphQLObjectType('Query', fields={'nodes': GraphQLField(GraphQLList(Node), resolver=lambda *_, **__: range(3))})
153+
154+
schema = GraphQLSchema(query=Query)
155+
document_ast = parse('''query MyQuery {
156+
nodes {
157+
id
158+
}
159+
}''')
160+
query_builder = QueryBuilder(schema, document_ast)
161+
QueryFragment = query_builder.get_operation_fragment('MyQuery')
162+
root = None
163+
expected = {
164+
'nodes': [{
165+
'id': n
166+
} for n in range(3)]
167+
}
168+
assert QueryFragment.resolver(lambda: root) == expected

graphql/execution/tests/test_benchmark.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
GraphQLSchema, Source, execute, parse)
66

77

8+
SIZE = 10000
9+
810
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)]
1012

1113
def resolve_all_ints(root, args, context, info):
1214
return big_int_list
@@ -28,8 +30,8 @@ def resolve_all_ints(root, args, context, info):
2830

2931

3032

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)]
3335
from ..executor import complete_leaf_value
3436
# def convert_item(i):
3537
# return i
@@ -42,6 +44,32 @@ def convert_list():
4244
benchmark(convert_list)
4345

4446

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+
4573
def test_big_list_of_containers_with_one_field(benchmark):
4674
Container = namedtuple('Container', 'x y z o')
4775

@@ -52,7 +80,7 @@ def test_big_list_of_containers_with_one_field(benchmark):
5280
'o': GraphQLField(GraphQLInt),
5381
})
5482

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)]
5684

5785
def resolve_all_containers(root, args, context, info):
5886
return big_container_list
@@ -83,7 +111,7 @@ def test_big_list_of_containers_with_multiple_fields(benchmark):
83111
'o': GraphQLField(GraphQLInt),
84112
})
85113

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)]
87115

88116
def resolve_all_containers(root, args, context, info):
89117
return big_container_list

0 commit comments

Comments
 (0)