New submission from Skip Montanaro <[EMAIL PROTECTED]>:
I noticed a colleague at work today checked in a change to his code to
switch back from subprocess.Popen to os.popen. I asked him about it and he
reported that subprocess.Popen was about 10x slower than os.popen. I asked
him for a simple test case, which is attached. Here are my results with
Python 2.4 through 2.7 (aka CVS HEAD):
tmp% python2.4 popentest.py
time with os.popen : 0.09
time with subprocess.Popen : 2.27
tmp% python2.5 popentest.py
time with os.popen : 0.03
time with subprocess.Popen : 1.52
tmp% python2.6 popentest.py
time with os.popen : 0.038824
time with subprocess.Popen : 1.517056
tmp% python2.7 popentest.py
time with os.popen : 0.033746
time with subprocess.Popen : 1.512331
These times are on my Mac laptop, all writing to the local disk. It seems
there was a bit of improvement in the 2.5 release but that it is still
miserably slow when compared with os.popen.
His original test used time.clock() as the timer. I changed to time.time()
but got essentially the same result.
Skip
----------
files: popentest.py
messages: 75173
nosy: skip.montanaro
severity: normal
status: open
title: Miserable subprocess.Popen performance
Added file: http://bugs.python.org/file11871/popentest.py
_______________________________________
Python tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue4194>
_______________________________________
import os, subprocess, time
os_filename = "tmp_os"
sub_filename = "tmp_subprocess"
def write_file(filename): # write out a reasonably big file
fh = file(filename, 'w')
for i in xrange(100000):
print >>fh, i
fh.close()
write_file(os_filename)
write_file(sub_filename)
start = time.time()
read_handle = os.popen('cat %s' % os_filename)
a = [i for i in read_handle]
print "time with os.popen : ", time.time() - start
start = time.time()
read_handle = subprocess.Popen(['cat', sub_filename],
stdout=subprocess.PIPE).stdout
a = [i for i in read_handle]
print "time with subprocess.Popen : ", time.time() - start
os.unlink(os_filename)
os.unlink(sub_filename)
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com