Created
January 29, 2014 17:19
-
-
Save danilochilene/8692598 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
### Testing MongoDB mass insert with pymongo | |
import pymongo | |
mongo = pymongo.Connection('localhost') | |
mongo_db = mongo['test'] | |
mongo_collection = mongo_db['masstest'] | |
n = 1 | |
limit = 100000 | |
firstnames = [ "John", "Jim", "James", "Sarah", "Anna", "Maria", "Sophia", "Martin", "Nick", "Bart" ] | |
while n <= limit: | |
for name in firstnames: | |
insert = mongo_collection.insert({ | |
'name': name | |
}) | |
n = n +1 | |
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
Result: | |
bicofino@ambush:~$ time python2.7 test_pymongo.py | |
real 1m25.385s | |
user 1m16.104s | |
sys 0m8.608s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment