Last active
December 18, 2015 17:09
-
-
Save yanmhlv/5816819 to your computer and use it in GitHub Desktop.
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
# coding: utf-8 | |
from mongoengine import * | |
import random, string | |
import minimongo as mm | |
from pymongo import MongoClient | |
class MongoEngine_Model1(DynamicDocument): | |
a = StringField() | |
meta = {'collection': 'test'} | |
class MongoEngine_Model2(Document): | |
a = StringField() | |
meta = {'collection': 'test'} | |
class MM_Model(mm.Model): | |
class Meta: | |
collection = 'test' | |
database = 'test' | |
indices = ( | |
mm.Index("_id"), | |
) | |
if __name__ == '__main__': | |
import timeit | |
random.seed(0) | |
connect('test') | |
conn = MongoClient() | |
db = conn['test'] | |
def test_minimongo(x): | |
a = MM_Model() | |
data = ''.join([random.choice(string.ascii_lowercase) for i in range(10)]) | |
a.a = data | |
a.save() | |
def test_mongoengine1(x): | |
data = ''.join([random.choice(string.ascii_lowercase) for i in range(10)]) | |
a = MongoEngine_Model1(a = data) | |
a.save() | |
def test_mongoengine2(x): | |
data = ''.join([random.choice(string.ascii_lowercase) for i in range(10)]) | |
a = MongoEngine_Model2(a = data) | |
a.save() | |
def test_pymongo(x): | |
data = ''.join([random.choice(string.ascii_lowercase) for i in range(10)]) | |
db.test.save({'a': data}) | |
db.test.remove() | |
test_me1 = timeit.Timer(lambda: map(test_mongoengine1, range(1000))) | |
print 'mongoengine DynamicDocument', test_me1.repeat(number = 10, repeat = 3) | |
print db.test.count() | |
db.test.remove() | |
test_me2 = timeit.Timer(lambda: map(test_mongoengine2, range(1000))) | |
print 'mongoengine2 Document', test_me2.repeat(number = 10, repeat = 3) | |
print db.test.count() | |
db.test.remove() | |
test_mm = timeit.Timer(lambda: map(test_minimongo, range(1000))) | |
print 'minimongo', test_mm.repeat(number = 10, repeat = 3) | |
print db.test.count() | |
db.test.remove() | |
test_pm = timeit.Timer(lambda: map(test_pymongo, range(1000))) | |
print 'pymongo', test_pm.repeat(number = 10, repeat = 3) | |
print db.test.count() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment