Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 4 docs per minute, 240 per hour, 5760 per day, 2.1 M per year
- import datetime
- import pymongo
- import time
- c = pymongo.Connection()
- c.drop_database('testdb')
- db = c.testdb
- year = 2010
- docno = 0
- start = time.time()
- db.test.ensure_index([('date', 1)])
- for month in range(1, 13):
- month_docs = 0
- month_start = time.time()
- dt = datetime.datetime(year, month, 1)
- print dt.isoformat(' ')
- while True:
- # Generate documents for the day
- docs = []
- # 4 docs per minute
- for minutes in range(60 * 24):
- for i in range(4):
- docs.append({
- 'date': dt + datetime.timedelta(minutes=minutes),
- 'str0': 'a',
- 'str1': 'b',
- 'val': docno,
- })
- docno += 1
- db.test.insert(docs, safe=True)
- month_docs += len(docs)
- try:
- dt = dt.replace(day=dt.day + 1)
- except ValueError:
- # Next month
- break
- print 'inserted %s docs in %.1f seconds' % (
- month_docs, time.time() - month_start
- )
- print 'inserted %s docs total in %.1f seconds' % (
- docno, time.time() - start
- )
Add Comment
Please, Sign In to add comment