Created
August 10, 2017 15:54
-
-
Save nhumrich/3470f075ae1d868f663b162d01a07838 to your computer and use it in GitHub Desktop.
asyncpgsa benchmark against aiopg.sa
This file contains 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 aiopg | |
import aiopg.sa | |
import asyncpg | |
import asyncpgsa | |
import sqlalchemy as sa | |
pg_tables = sa.Table( | |
'pg_tables', sa.MetaData(), | |
sa.Column('schemaname'), | |
sa.Column('tablename'), | |
sa.Column('tableowner'), | |
sa.Column('tablespace'), | |
sa.Column('hasindexes') | |
) | |
query = pg_tables.select().where(pg_tables.c.schemaname == 'pg_catalog') | |
loop = asyncio.get_event_loop() | |
async def aio_coro(): | |
await connection.execute(query) | |
async def apg_coro(): | |
await pgconn.execute(query) | |
run_aiopg = lambda: loop.run_until_complete(aio_coro()) | |
run_asyncpgsa = lambda: loop.run_until_complete(apg_coro()) | |
pgconn = asyncpg.connect(user='postgres', host='127.0.0.1', password='password', database='postgres', connection_class=asyncpgsa.connection.SAConnection) | |
pgconn = loop.run_until_complete(pgconn) | |
engine = loop.run_until_complete(aiopg.sa.create_engine(user='postgres', password='password', host='127.0.0.1', database='postgres')) | |
connection = loop.run_until_complete(engine.acquire()) | |
run_asyncpgsa() | |
run_aiopg() | |
from timeit import timeit | |
print('aiopg.sa:', timeit(run_aiopg, number=10000)) | |
print('asyncpgsa', timeit(run_asyncpgsa, number=10000)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi!
I've added also raw-query performance over
asyncpg
for comparing it with raw queries performance, still pretty impressive: