Skip to content

Instantly share code, notes, and snippets.

@dongweiming
Last active January 4, 2016 05:49
Show Gist options
  • Save dongweiming/8578154 to your computer and use it in GitHub Desktop.
Save dongweiming/8578154 to your computer and use it in GitHub Desktop.
import multiprocessing
import time
import pymongo
start = time.time()
db = pymongo.MongoClient()['test']
def mapper(i):
if i['a'] > 0.95:
pass
pool_size = multiprocessing.cpu_count() * 2
pool = multiprocessing.Pool(pool_size)
pool.map(mapper, db.test.find(), chunksize=1000)
pool.close()
pool.join()
end = time.time()
print 'cost: ', end - start
mport pymongo
import time
db = pymongo.MongoClient()['test']
start = time.time()
for i in db.test.find():
if i['a'] < 0.95:
pass
end = time.time()
print 'cost: ', end - start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment