import pymongo
import time
import re
db = pymongo.Connection()['barn']
def test_mongo_logic():
start = time.time()
count = 0
total = 0
for item in db.cache.find({'$where': 'function(){return this.url.search(/10/) > -1}'}):
count += 1
if count == 10000:
break
print item['_id'], total
print '%.2f' % (time.time() - start)
def test_python_logic():
start = time.time()
count = 0
total = 0
rex = re.compile(r'10')
for item in db.cache.find({}):
if rex.search(item['url']):
count += 1
if count == 10000:
break
print item['_id'], total
print '%.2f' % (time.time() - start)
if __name__ == '__main__':
test_mongo_logic()
test_python_logic()