def test_find_update():
db = Connection()
db.drop_collection("test")
db.test.insert({"x":1,"y":2})
start = time.time()
for i in range(1,10000):
y = db.test.find_one()
print db.test.find_one()
print time.time()-start
db.drop_collection("test")
start = time.time()
for i in range(1,10000):
db.test.insert({"x":1,"y":2})
print db.test.find_one()
print time.time()-start
db.drop_collection("test")
db.test.insert({"x":1,"y":2})
start = time.time()
for i in range(1,10000):
db.test.update({},{"$inc":{"x":1,"y":2}})
print db.test.find_one()
print time.time()-start
結果:
{u'y': 2, u'x': 1, u'_id': ObjectId('4ffd159ae3f0f8103a000000')}
**9.78821802139**
{u'y': 2, u'x': 1, u'_id': ObjectId('4ffd15a4e3f0f8103a000001')}
**0.82381606102**
{u'y': 200000, u'x': 100000, u'_id': ObjectId('4ffd15a5e3f0f8103a002710')}
**0.635884046555**
find演算子はとても安いかもしれないと思いますが、それは私の仮定とは反対です。検索演算子に時間がかかる理由を誰かに教えてもらえますか?