Skip to content

Instantly share code, notes, and snippets.

@ketuls
Created January 7, 2015 10:48
Show Gist options
  • Save ketuls/c40f9e98d47d81afaf67 to your computer and use it in GitHub Desktop.
Save ketuls/c40f9e98d47d81afaf67 to your computer and use it in GitHub Desktop.
This file reads the data inserted by postgres_generate.py. Time required to read the data is printed on terminal. Sample command would be "python postgres_reader.py <Number of records to be fetched>".
import psycopg2
import json
import md5
import couchdb
import random
import sys
from datetime import datetime
conn_string= "host='localhost' dbname='postgres' user='ketulshah'"
cur= psycopg2.connect(conn_string).cursor()
count = int(sys.argv[1]);
startTime = datetime.now()
m = []
for i in range(count):
m.append((md5.md5(str(random.randint(10,100000))).hexdigest()),)
queryTime = datetime.now()
cur.execute("select des from img_des1 where id = ANY(%s)",(m,))
rows= cur.fetchall();
for r in rows:
x= r[0][0][0]
x+=1
print("Read 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