Created
August 25, 2019 19:18
-
-
Save ktosiek/849e8c7de8852c2df1df5af8ac193287 to your computer and use it in GitHub Desktop.
Graphene: serialize 100k objects, v2 vs v3
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
Graphene 2: 6.852552616968751 | |
Graphene 3: 15.776521055027843 |
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 graphene | |
class UserQuery(graphene.ObjectType): | |
id = graphene.Int() | |
class Query(graphene.ObjectType): | |
users = graphene.List(UserQuery) | |
def resolve_users(self, info): | |
return users | |
class User(object): | |
def __init__(self, id): | |
self.id = id | |
users = [User(index) for index in range(0, 100_000)] | |
schema = graphene.Schema(query=Query) | |
import timeit | |
print( | |
timeit.timeit(lambda: schema.execute('{ users { id } }').data, number=10) | |
) |
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
#!/usr/bin/env bash | |
python3 -mvenv _env_g2 | |
./_env_g2/bin/pip install graphene==2.1.8 | |
python3 -mvenv _env_g3 | |
./_env_g3/bin/pip install graphene==3.0.dev20190817210753 | |
echo -n 'Graphene 2: ' | |
./_env_g2/bin/python test.py | |
echo -n 'Graphene 3: ' | |
./_env_g3/bin/python test.py |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment