Created
February 5, 2020 12:39
-
-
Save jedie/45ddf8ee7e24704c9485eb8cbcf9ba13 to your computer and use it in GitHub Desktop.
Benchmark Tartiflette
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import cProfile | |
import pstats | |
import time | |
from collections import OrderedDict, namedtuple | |
from tartiflette import Resolver, create_engine | |
Entry = namedtuple('Entry', 'id name') | |
entries = [Entry(id=f'id{i}', name=f'Entry Name {i}') for i in range(1000)] | |
@Resolver("Query.entry") | |
async def resolver_entry(parent, args, context, info): | |
return entries | |
async def run(): | |
sdl = """ | |
type Entry { | |
id: String! | |
name: String | |
} | |
type Query { | |
entry: [Entry] | |
} | |
""" | |
engine = await create_engine(sdl=sdl) | |
start_time = time.monotonic() | |
result = await engine.execute(query='query { entry { id name } }') | |
duration = time.monotonic() - start_time | |
print(f'takes: {duration*1000:.1f} ms') | |
entries = result["data"]["entry"] | |
assert len(entries) == 1000, len(entries) | |
assert entries[0] == OrderedDict( | |
[('id', 'id0'), ('name', 'Entry Name 0')]), entries[0] | |
assert entries[999] == OrderedDict( | |
[('id', 'id999'), ('name', 'Entry Name 999')]), entries[999] | |
print() | |
print('_' * 100) | |
print('run cProfile...\n') | |
pr = cProfile.Profile() | |
pr.enable() | |
await engine.execute(query='query { entry { id name } }') | |
pr.disable() | |
pstats.Stats(pr).sort_stats('tottime', 'cumulative', 'calls').print_stats(20) | |
if __name__ == "__main__": | |
loop = asyncio.get_event_loop() | |
loop.run_until_complete(run()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
takes: 57.7 ms | |
____________________________________________________________________________________________________ | |
run cProfile... | |
216243 function calls in 0.108 seconds | |
Ordered by: internal time, cumulative time, call count | |
List reduced from 100 to 20 due to restriction <20> | |
ncalls tottime percall cumtime percall filename:lineno(function) | |
1001 0.013 0.000 0.014 0.000 /home/jens/.local/share/virtualenvs/foo-bar/lib/python3.6/site-packages/tartiflette/execution/execute.py:137(<listcomp>) | |
7004 0.007 0.000 0.101 0.000 /usr/lib/python3.6/asyncio/events.py:143(_run) | |
1003 0.006 0.000 0.027 0.000 /usr/lib/python3.6/asyncio/tasks.py:568(gather) | |
9 0.005 0.001 0.108 0.012 /usr/lib/python3.6/asyncio/base_events.py:1355(_run_once) | |
3001 0.004 0.000 0.012 0.000 /usr/lib/python3.6/asyncio/base_events.py:297(create_task) | |
2001 0.004 0.000 0.008 0.000 /home/jens/.local/share/virtualenvs/foo-bar/lib/python3.6/site-packages/tartiflette/resolver/factory.py:17(resolve_field_value_or_error) | |
7004 0.004 0.000 0.008 0.000 /usr/lib/python3.6/asyncio/base_events.py:611(_call_soon) | |
4000 0.004 0.000 0.055 0.000 /home/jens/.local/share/virtualenvs/foo-bar/lib/python3.6/site-packages/tartiflette/coercers/outputs/directives_coercer.py:6(output_directives_coercer) | |
7004 0.003 0.000 0.012 0.000 /usr/lib/python3.6/asyncio/base_events.py:581(call_soon) | |
7004 0.003 0.000 0.004 0.000 /usr/lib/python3.6/asyncio/events.py:104(__init__) | |
4002 0.003 0.000 0.066 0.000 /home/jens/.local/share/virtualenvs/foo-bar/lib/python3.6/site-packages/tartiflette/coercers/outputs/common.py:44(complete_value_catching_error) | |
2002 0.003 0.000 0.040 0.000 /home/jens/.local/share/virtualenvs/foo-bar/lib/python3.6/site-packages/tartiflette/execution/execute.py:108(execute_fields) | |
2002 0.002 0.000 0.032 0.000 /home/jens/.local/share/virtualenvs/foo-bar/lib/python3.6/site-packages/tartiflette/execution/execute.py:23(resolve_field) | |
3001 0.002 0.000 0.017 0.000 /usr/lib/python3.6/asyncio/tasks.py:507(ensure_future) | |
4002 0.002 0.000 0.058 0.000 /home/jens/.local/share/virtualenvs/foo-bar/lib/python3.6/site-packages/tartiflette/coercers/outputs/null_coercer.py:15(wrapper) | |
2000 0.002 0.000 0.046 0.000 /home/jens/.local/share/virtualenvs/foo-bar/lib/python3.6/site-packages/tartiflette/coercers/outputs/common.py:86(complete_object_value) | |
1001 0.002 0.000 0.003 0.000 /home/jens/.local/share/virtualenvs/foo-bar/lib/python3.6/site-packages/tartiflette/execution/collect.py:185(collect_fields) | |
2002 0.002 0.000 0.026 0.000 /home/jens/.local/share/virtualenvs/foo-bar/lib/python3.6/site-packages/tartiflette/resolver/factory.py:86(resolve_field) | |
2001 0.002 0.000 0.004 0.000 /home/jens/.local/share/virtualenvs/foo-bar/lib/python3.6/site-packages/tartiflette/execution/helpers.py:4(get_field_definition) | |
3001 0.002 0.000 0.004 0.000 /usr/lib/python3.6/asyncio/tasks.py:622(_done_callback) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
related issues: