Created
October 3, 2015 13:40
-
-
Save ringerc/7642350fee9f729d1466 to your computer and use it in GitHub Desktop.
Compare disconnect/reconnect and pooled times
This file contains hidden or 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
#!/usr/bin/env python | |
# | |
# Disconnect/reconnect each query | |
# | |
# Takes 0.45s to run here | |
# | |
import time | |
import psycopg2 | |
start_t = time.time() | |
for x in range(1, 100): | |
conn = psycopg2.connect('dbname=test') | |
curs = conn.cursor() | |
curs.execute("SELECT 1;") | |
curs.fetchall() | |
curs.close() | |
conn.close() | |
end_t = time.time() | |
print "Elapsed: ", end_t - start_t |
This file contains hidden or 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
#!/usr/bin/env python | |
# | |
# Re-use connection | |
# | |
# Takes 0.01s to run here | |
import time | |
import psycopg2 | |
start_t = time.time() | |
conn = psycopg2.connect('dbname=test') | |
for x in range(1, 100): | |
curs = conn.cursor() | |
curs.execute("SELECT 1;") | |
curs.fetchall() | |
curs.close() | |
conn.close() | |
end_t = time.time() | |
print "Elapsed: ", end_t - start_t |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment