Skip to content

Commit a08f108

Browse files
author
James William Pye
committed
Update to use the new APIs.
1 parent ab5ed57 commit a08f108

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

postgresql/test/perf_copy_io.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
##
55
# Copy I/O: To and From performance
66
##
7-
import os, sys, gc, random, time
7+
import os, sys, random, time
88

99
if __name__ == '__main__':
10-
Words = open('/usr/share/dict/words').readlines()
10+
with open('/usr/share/dict/words', mode='brU') as wordfile:
11+
Words = wordfile.readlines()
1112
else:
12-
Words = ['/usr/share/dict/words', 'is', 'read', 'in', '__main__']
13+
Words = [b'/usr/share/dict/words', b'is', b'read', b'in', b'__main__']
1314
wordcount = len(Words)
1415
random.seed()
1516

@@ -21,22 +22,23 @@ def testSpeed(tuples = 50000 * 3):
2122
execute("CREATE TEMP TABLE _copy "
2223
"(i int, t text, mt text, ts text, ty text, tx text);")
2324
try:
24-
Q = query("COPY _copy FROM STDIN")
25+
Q = prepare("COPY _copy FROM STDIN")
2526
size = [0]
2627
def incsize(data):
28+
'count of bytes'
2729
size[0] += len(data)
2830
return data
2931
sys.stderr.write("preparing data(%d tuples)...\n" %(tuples,))
3032

3133
# Use an LC to avoid the Python overhead involved with a GE
32-
data = [incsize('\t'.join((
33-
str(x), getWord(), getWord(),
34+
data = [incsize(b'\t'.join((
35+
str(x).encode('ascii'), getWord(), getWord(),
3436
getWord(), getWord(), getWord()
35-
)))+'\n' for x in range(tuples)]
37+
)))+b'\n' for x in range(tuples)]
3638

3739
sys.stderr.write("starting copy...\n")
3840
start = time.time()
39-
copied_in = Q(data)
41+
copied_in = Q.load(data)
4042
duration = time.time() - start
4143
sys.stderr.write(
4244
"COPY FROM STDIN Summary,\n " \
@@ -52,7 +54,7 @@ def incsize(data):
5254
tuples / duration,
5355
)
5456
)
55-
Q = query("COPY _copy TO STDOUT")
57+
Q = prepare("COPY _copy TO STDOUT")
5658
start = time.time()
5759
c = 0
5860
for x in Q():

0 commit comments

Comments
 (0)