python disk i/o speed

Delaney, Timothy tdelaney at
Thu Aug 8 02:10:29 CEST 2002

> From: pruebauno at [mailto:pruebauno at]

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 = [

    out = '"' + '","'.join(out) + '"\n'


    # formatting
    out = '"%s","%s","%s","%s"\n' % (part0, part1, 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