mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-14 05:36:45 +03:00
Added simple benchmarks
This commit is contained in:
parent
bf5e0e2881
commit
0f76e8f817
|
@ -23,7 +23,7 @@ before_install:
|
||||||
install:
|
install:
|
||||||
- |
|
- |
|
||||||
if [ "$TEST_TYPE" = build ]; then
|
if [ "$TEST_TYPE" = build ]; then
|
||||||
pip install pytest pytest-cov coveralls six
|
pip install pytest pytest-cov pytest-benchmark coveralls six
|
||||||
pip install -e .
|
pip install -e .
|
||||||
python setup.py develop
|
python setup.py develop
|
||||||
elif [ "$TEST_TYPE" = lint ]; then
|
elif [ "$TEST_TYPE" = lint ]; then
|
||||||
|
|
|
@ -153,3 +153,9 @@ def test_objecttype_as_container_invalid_kwargs():
|
||||||
Container(unexisting_field="3")
|
Container(unexisting_field="3")
|
||||||
|
|
||||||
assert "'unexisting_field' is an invalid keyword argument for Container" == str(excinfo.value)
|
assert "'unexisting_field' is an invalid keyword argument for Container" == str(excinfo.value)
|
||||||
|
|
||||||
|
|
||||||
|
def test_objecttype_container_benchmark(benchmark):
|
||||||
|
@benchmark
|
||||||
|
def create_objecttype():
|
||||||
|
Container(field1='field1', field2='field2')
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
|
from graphql import execute, Source, parse
|
||||||
|
|
||||||
from ..objecttype import ObjectType
|
from ..objecttype import ObjectType
|
||||||
from ..scalars import String
|
from ..scalars import String, Int
|
||||||
from ..schema import Schema
|
from ..schema import Schema
|
||||||
|
from ..structures import List
|
||||||
|
|
||||||
|
|
||||||
def test_query():
|
def test_query():
|
||||||
|
@ -50,3 +53,117 @@ def test_query_middlewares():
|
||||||
executed = hello_schema.execute('{ hello, other }')
|
executed = hello_schema.execute('{ hello, other }')
|
||||||
assert not executed.errors
|
assert not executed.errors
|
||||||
assert executed.data == {'hello': 'dlroW', 'other': 'rehto'}
|
assert executed.data == {'hello': 'dlroW', 'other': 'rehto'}
|
||||||
|
|
||||||
|
|
||||||
|
def test_big_list_query_benchmark(benchmark):
|
||||||
|
big_list = range(10000)
|
||||||
|
|
||||||
|
class Query(ObjectType):
|
||||||
|
all_ints = List(Int)
|
||||||
|
|
||||||
|
def resolve_all_ints(self, args, context, info):
|
||||||
|
return big_list
|
||||||
|
|
||||||
|
hello_schema = Schema(Query)
|
||||||
|
|
||||||
|
big_list_query = partial(hello_schema.execute, '{ allInts }')
|
||||||
|
result = benchmark(big_list_query)
|
||||||
|
assert not result.errors
|
||||||
|
assert result.data == {'allInts': big_list}
|
||||||
|
|
||||||
|
|
||||||
|
def test_big_list_query_compiled_query_benchmark(benchmark):
|
||||||
|
big_list = range(10000)
|
||||||
|
|
||||||
|
class Query(ObjectType):
|
||||||
|
all_ints = List(Int)
|
||||||
|
|
||||||
|
def resolve_all_ints(self, args, context, info):
|
||||||
|
return big_list
|
||||||
|
|
||||||
|
hello_schema = Schema(Query)
|
||||||
|
source = Source('{ allInts }')
|
||||||
|
query_ast = parse(source)
|
||||||
|
|
||||||
|
big_list_query = partial(execute, hello_schema, query_ast)
|
||||||
|
result = benchmark(big_list_query)
|
||||||
|
assert not result.errors
|
||||||
|
assert result.data == {'allInts': big_list}
|
||||||
|
|
||||||
|
|
||||||
|
def test_big_list_of_containers_query_benchmark(benchmark):
|
||||||
|
big_list = range(10000)
|
||||||
|
|
||||||
|
class Container(ObjectType):
|
||||||
|
x = Int()
|
||||||
|
|
||||||
|
class Query(ObjectType):
|
||||||
|
all_containers = List(Container)
|
||||||
|
|
||||||
|
def resolve_all_containers(self, args, context, info):
|
||||||
|
return (Container(x=x) for x in big_list)
|
||||||
|
|
||||||
|
hello_schema = Schema(Query)
|
||||||
|
|
||||||
|
big_list_query = partial(hello_schema.execute, '{ allContainers { x } }')
|
||||||
|
result = benchmark(big_list_query)
|
||||||
|
assert not result.errors
|
||||||
|
assert result.data == {'allContainers': [{'x': x} for x in big_list]}
|
||||||
|
|
||||||
|
|
||||||
|
def test_big_list_of_containers_multiple_fields_query_benchmark(benchmark):
|
||||||
|
big_list = range(10000)
|
||||||
|
|
||||||
|
class Container(ObjectType):
|
||||||
|
x = Int()
|
||||||
|
y = Int()
|
||||||
|
z = Int()
|
||||||
|
o = Int()
|
||||||
|
|
||||||
|
class Query(ObjectType):
|
||||||
|
all_containers = List(Container)
|
||||||
|
|
||||||
|
def resolve_all_containers(self, args, context, info):
|
||||||
|
return (Container(x=x, y=x, z=x, o=x) for x in big_list)
|
||||||
|
|
||||||
|
hello_schema = Schema(Query)
|
||||||
|
|
||||||
|
big_list_query = partial(hello_schema.execute, '{ allContainers { x, y, z, o } }')
|
||||||
|
result = benchmark(big_list_query)
|
||||||
|
assert not result.errors
|
||||||
|
assert result.data == {'allContainers': [{'x': x, 'y':x, 'z':x, 'o': x} for x in big_list]}
|
||||||
|
|
||||||
|
|
||||||
|
def test_big_list_of_containers_multiple_fields_custom_resolvers_query_benchmark(benchmark):
|
||||||
|
big_list = range(10000)
|
||||||
|
|
||||||
|
class Container(ObjectType):
|
||||||
|
x = Int()
|
||||||
|
y = Int()
|
||||||
|
z = Int()
|
||||||
|
o = Int()
|
||||||
|
|
||||||
|
def resolve_x(self, args, context, info):
|
||||||
|
return self.x
|
||||||
|
|
||||||
|
def resolve_y(self, args, context, info):
|
||||||
|
return self.y
|
||||||
|
|
||||||
|
def resolve_z(self, args, context, info):
|
||||||
|
return self.z
|
||||||
|
|
||||||
|
def resolve_o(self, args, context, info):
|
||||||
|
return self.o
|
||||||
|
|
||||||
|
class Query(ObjectType):
|
||||||
|
all_containers = List(Container)
|
||||||
|
|
||||||
|
def resolve_all_containers(self, args, context, info):
|
||||||
|
return (Container(x=x, y=x, z=x, o=x) for x in big_list)
|
||||||
|
|
||||||
|
hello_schema = Schema(Query)
|
||||||
|
|
||||||
|
big_list_query = partial(hello_schema.execute, '{ allContainers { x, y, z, o } }')
|
||||||
|
result = benchmark(big_list_query)
|
||||||
|
assert not result.errors
|
||||||
|
assert result.data == {'allContainers': [{'x': x, 'y':x, 'z':x, 'o': x} for x in big_list]}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user