33# copyright 2009, James William Pye
44# http://python.projects.postgresql.org
55##
6- # Query I/O: Mass insert and select performance
6+ # Statement I/O: Mass insert and select performance
77##
88import os
99import time
@@ -14,19 +14,19 @@ def insertSamples(count, insert_records):
1414 (- 3 , 123 , 0xfffffea023 , 'some_óäæ_thing' , 'varying' , 'æ' )
1515 for x in range (count )
1616 ]
17-
1817 gen = time .time ()
19- insert_records << recs
18+ insert_records . load ( recs )
2019 fin = time .time ()
2120 xacttime = fin - gen
2221 ats = count / xacttime
23- print >> sys .stderr , \
22+ sys .stderr . write (
2423 "INSERT Summary,\n " \
2524 "inserted tuples: %d\n " \
2625 "total time: %f\n " \
2726 "average tuples per second: %f\n " % (
2827 count , xacttime , ats ,
2928 )
29+ )
3030
3131def timeTupleRead (portal ):
3232 loops = 0
@@ -36,27 +36,28 @@ def timeTupleRead(portal):
3636 finalis = time .time ()
3737 looptime = finalis - genesis
3838 ats = loops / looptime
39- print >> sys .stderr , \
39+ sys .stderr . write (
4040 "SELECT Summary,\n " \
4141 "looped/tuples: %d\n " \
4242 "looptime: %f\n " \
4343 "average tuples per second: %f\n " % (loops , looptime , ats ,)
44+ )
4445
4546def main (count ):
4647 execute ('CREATE TEMP TABLE samples '
4748 '(i2 int2, i4 int4, i8 int8, t text, v varchar, c char)' )
48- insert_records = query (
49+ insert_records = prepare (
4950 "INSERT INTO samples VALUES ($1, $2, $3, $4, $5, $6)"
5051 )
51- select_records = query ("SELECT * FROM samples" )
52+ select_records = prepare ("SELECT * FROM samples" )
5253 try :
5354 insertSamples (count , insert_records )
5455 timeTupleRead (select_records ())
5556 finally :
5657 execute ("DROP TABLE samples" )
5758
5859def command (args ):
59- main (int ((args + [15000 ])[1 ]))
60+ main (int ((args + [25000 ])[1 ]))
6061
6162if __name__ == '__main__' :
6263 command (sys .argv )
0 commit comments