MCPcopy Index your code
hub / github.com/MongoEngine/mongoengine / test_big_doc

Function test_big_doc

benchmarks/test_basic_doc_ops.py:78–130  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

76
77
78def test_big_doc():
79 class Contact(EmbeddedDocument):
80 name = StringField()
81 title = StringField()
82 address = StringField()
83
84 class Company(Document):
85 name = StringField()
86 contacts = ListField(EmbeddedDocumentField(Contact))
87
88 Company.drop_collection()
89
90 def init_company():
91 return Company(
92 name="MongoDB, Inc.",
93 contacts=[
94 Contact(name="Contact %d" % x, title="CEO", address="Address %d" % x)
95 for x in range(1000)
96 ],
97 )
98
99 company = init_company()
100 print("Big doc to mongo: %.3fms" % (timeit(company.to_mongo, 100) * 10**3))
101
102 print("Big doc validation: %.3fms" % (timeit(company.validate, 1000) * 10**3))
103
104 company.save()
105
106 def save_company():
107 company._mark_as_changed("name")
108 company._mark_as_changed("contacts")
109 company.save()
110
111 print("Save to database: %.3fms" % (timeit(save_company, 100) * 10**3))
112
113 son = company.to_mongo()
114 print(
115 "Load from SON: %.3fms" % (timeit(lambda: Company._from_son(son), 100) * 10**3)
116 )
117
118 print(
119 "Load from database: %.3fms" % (timeit(lambda: Company.objects[0], 100) * 10**3)
120 )
121
122 def create_and_delete_company():
123 c = init_company()
124 c.save()
125 c.delete()
126
127 print(
128 "Init + save to database + delete: %.3fms"
129 % (timeit(create_and_delete_company, 10) * 10**3)
130 )
131
132
133if __name__ == "__main__":

Callers 1

Calls 6

init_companyFunction · 0.85
timeitFunction · 0.85
drop_collectionMethod · 0.80
_from_sonMethod · 0.80
saveMethod · 0.45
to_mongoMethod · 0.45

Tested by

no test coverage detected