|
From: Kent J. <ke...@td...> - 2005-02-17 16:33:36
|
Lauri Lehtinen wrote: > Setting to use the binary mode worked! > > Does any one know why java variant of this in jython performs very poorly? The first one is using unbuffered file I/O. The second one is copying one byte at a time. You need to combine the two - use Buffered[Input|Output]Stream *and* use a large copy buffer. Kent > > Here the basic java variant: > --- > from java.net import * > from java.io import * > def copy(filename): > bi = FileInputStream(File(filename)) > bo = FileOutputStream(File(filename+".copy")) > b = [1000000] > while 1: > l = bi.read(b) > if l == -1: > break > bo.write(b) bo.close() > bi.close() > return 1 > if __name__ == "__main__": i = raw_input("Give file:") > copy(i) > --- > That berforms only about 10kB/s, here one that uses buffers and performs > better: > --- > from java.net import * > from java.io import * > def copy(filename): > bi = BufferedInputStream(FileInputStream(File(filename))) > bo = BufferedOutputStream(FileOutputStream(File(filename+".copy"))) > while 1: > l = bi.read() > if l == -1: > break > bo.write(l) bo.close() > bi.close() > return 1 > if __name__ == "__main__": i = raw_input("Give file:") > copy(i) > --- > This performs about 600kB/s what isn't good at all, that should be much > better. I tried also by using static buffer size but that performed even > poorly for some reason. Why the performance is so bad? > > Sincerely, > Lauri Lehtinen > |