python disk i/o speed
Delaney, Timothy
tdelaney at avaya.com
Wed Aug 7 20:10:29 EDT 2002
> From: pruebauno at latinmail.com [mailto:pruebauno at latinmail.com]
I can spot a few immediate problems:
1. In the Python code, you are never closing the file. Always explicitly
close the file.
2. You are using string concatenation for both the Python and java code.
This is bad for performance (a new string needs to be created every time.
This is almost certainly downing out the I/O characteristics.
Python options: use string formatting or list joining.
# joining
out = [
part0,
part1,
part2,
str(int(part0)+int(part1)+int(part2)),
]
out = '"' + '","'.join(out) + '"\n'
output.write(out)
# formatting
out = '"%s","%s","%s","%s"\n' % (part0, part1, part2,
int(part0)+int(part1)+int(part2),)
As you can see, formatting is much clearer, and is probably going to be
fastest in this case (everything is done in C code).
Java options: Use a StringBuffer or java.text.MessageFormat (effectively
string formatting). I'll leave the code up to you. It's less pretty.
Tim Delaney
More information about the Python-list
mailing list