Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
asyncpgsa benchmark against aiopg.sa
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))
@prokaktus

This comment has been minimized.

Copy link

@prokaktus prokaktus commented Nov 1, 2019

Hi!

I've added also raw-query performance over asyncpg for comparing it with raw queries performance, still pretty impressive:

raw 6.719434757
aiopg.sa: 8.542597448
asyncpgsa 7.121963994
@nhumrich

This comment has been minimized.

Copy link
Owner Author

@nhumrich nhumrich commented Dec 4, 2019

Awesome. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment