Skip to content

Instantly share code, notes, and snippets.

@ipfans
Created November 19, 2015 07:49
Show Gist options
  • Save ipfans/267548132823740468d4 to your computer and use it in GitHub Desktop.
Save ipfans/267548132823740468d4 to your computer and use it in GitHub Desktop.
MongoEngine Beachmark on CPython 2.7.10&pypy 4.0.0
#!/usr/bin/env python
# coding=utf-8
from __future__ import absolute_import, division, print_function
import datetime
import time
from mongoengine import (DateTimeField, Document, ListField, StringField,
connect)
connect(db="mongoengine")
class BlogPost(Document):
title = StringField(required=True, max_length=200)
posted = DateTimeField(default=datetime.datetime.now)
tags = ListField(StringField(max_length=50))
meta = {'allow_inheritance': True}
class TextPost(BlogPost):
content = StringField(required=True)
class LinkPost(BlogPost):
url = StringField(required=True)
def save_100000x2_post():
for x in xrange(0, 100000):
post1 = TextPost(title='TextPost %d' % x, content='See the tutorial')
post1.tags = ['mongodb', 'mongoengine']
post1.save()
post2 = LinkPost(title='MongoEngine Docs %d' % x, url='hmarr.com')
post2.tags = ['mongoengine', 'documentation']
post2.save()
def read_200000_post():
for post in BlogPost.objects():
title = post.title
if __name__ == '__main__':
start = time.time()
start_save = int(time.time())
save_100000x2_post()
savetime = time.time() - start_save
start_read = time.time()
read_200000_post()
readtime = time.time() - start_read
print("save spent: {}".format(savetime))
print("read spent: {}".format(readtime))
print("all spent: {}".format(time.time() - start))
# MongoEngine 0.10.1+PyMongo 3.1.1
# CPython 2.7.10
~ python bench.py
save spent: 246.837469101
read spent: 40.0638878345
all spent: 286.062906981
# Pypy-4.0.0
~ pypy mongoengine_bench.py
save spent: 126.907922983
read spent: 8.06250905991
all spent: 134.843950987
@ipfans
Copy link
Author

ipfans commented Nov 25, 2015

MongoEngine 0.10.1+PyMongo 3.1.1 on Linux

(pyenv)[root@xxx ~]# python bench.py
save spent: 431.019099951
read spent: 47.6389639378
all spent: 478.258651972

(pypyenv)[root@xxx ~]# pypy bench.py
save spent: 296.965039015
read spent: 20.2039370537
all spent: 316.866650105

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