Last active
January 4, 2016 05:49
-
-
Save dongweiming/8578154 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
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 |
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
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