Skip to content

Instantly share code, notes, and snippets.

@ketuls
Created January 7, 2015 10:53
Show Gist options
  • Save ketuls/da05d0485ffcbd46a302 to your computer and use it in GitHub Desktop.
Save ketuls/da05d0485ffcbd46a302 to your computer and use it in GitHub Desktop.
This file inserts random image descriptors in Couch DB. # of records to be inserted is passed as argument. It assumes that couchdb is locally installed and running. All the modules of import list needs to be installed to use this. Sample command would be "python couchdb_generate.py <Number of records>" . Table Name will be "test"+<Numberofrecords>.
import json
import md5
import couchdb
import random
import sys
from datetime import datetime
count = int(sys.argv[1]);
couch = couchdb.Server()
db_name='test'+str(count)
try:
db = couch.create(db_name)
except:
couch.delete(db_name)
db = couch.create(db_name)
bp = 1000
mod = count/bp;
startTime = datetime.now()
for j in range(mod):
des=[]
m = []
si = j * bp
ei = si + bp
print si
print ei
for i in range(si,ei):
des.append([[random.randint(1,255) for r in xrange(32)] for p in xrange(500)])
m.append(md5.md5(str(i)).hexdigest())
queryTime = datetime.now()
for i in range(bp):
db.save({'_id':m[i],'d':des[i]})
print("Insert Time is ")
print datetime.now() - queryTime
print("Script Tme is ")
print datetime.now() - startTime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment