why python is slower than java?
kosh
kosh at aesaeion.com
Sun Nov 7 00:15:16 EST 2004
On Saturday 06 November 2004 4:10 am, Alex Martelli wrote:
> with Python 2.4 beta 1 for the roughly equivalent:
>
> inputFile = file("/usr/share/dict/web2", 'r')
> outputFile = file("/tmp/acopy", 'w')
>
> outputFile.write(inputFile.read())
>
> inputFile.close()
> outputFile.close()
>
I think a generator version works even better. I did tests at various files
sizes and overall the generator one was better and it was vastly better at
large file sizes and overall the generator one also impacted the system less.
The regular version which reads the whole file at once get really bad with
large files especially if the system is being used.
I suspect the generator version should work with any size file that the os is
capable of working with and should be resource friendly at any size.
Just thought the generator version would be a good comparison to the java
version and strangely enough in many cases it is actually faster then the
regular version. :)
Generator Version:
inputFile = file("/home/kosh/KNOPPIX_V3.6-2004-08-16-EN.iso", 'r')
outputFile = file("/tmp/acopy", 'w')
outputFile.writelines(inputFile)
inputFile.close()
outputFile.close()
Regular Version:
inputFile = file("/home/kosh/temp.txt", 'r')
outputFile = file("/tmp/acopy", 'w')
outputFile.write(inputFile.read())
inputFile.close()
outputFile.close()
The timing was done with python 2.3.4 on debian/sid
Large File Test:
File Copied: 733499392 KNOPPIX_V3.6-2004-08-16-EN.iso
Real User Sys
Gen 0m33.478s 0m4.302s 0m3.542s
Reg 2m28.029s 0m0.010s 0m4.992s *
Reg 0m34.913s 0m0.009s 0m4.713s
* This is how long the first run took. The machine swapped
heavily. The Other time is for subsequent runs. This method
overall uses a massive ammount of ram.
Memory Usage:
Virt Res Shr
Gen 3816K 2364K 2524K
Reg 703M 700M 2524K
Small File Test
File Copied: 2754459 Zope-2.7.2-0.tgz
Real User Sys
Gen 0m0.049s 0m0.023s 0m0.014s
Reg 0m0.037s 0m0.009s 0m0.019s
Tiny File Test:
File Copied: 205 May temp.txt
Real User Sys
Gen 0m0.012s 0m0.007s 0m0.005s
Reg 0m0.028s 0m0.009s 0m0.003s
More information about the Python-list
mailing list