python disk i/o speed

nnes pruebauno at latinmail.com
Fri Aug 9 10:50:49 EDT 2002


"Delaney, Timothy" <tdelaney at avaya.com> wrote in message news:<mailman.1028765472.4175.python-list at python.org>...
> > From: pruebauno at latinmail.com [mailto:pruebauno at latinmail.com]
> 
> I can spot a few immediate problems:
> 
> 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.
> 
>     # 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

I can´t reproduce your claimings in practice.

After reading:

http://developer.java.sun.com/developer/
technicalArticles/Programming/PerfTuning/#FormattingCosts

I replaced:

out.write('"%s","%s","%s","%i"\n' % (
x,y,z,localint(x) + localint(y) + localint(z)))

by:

out.write('"'+x+'","'+y+'","'+z+'","'+str(
localint(x) + localint(y) + localint(z))+'"\n')

and my programm finished a half-second faster, which doesn´t make
sense to me, since there is an additional str() call involved. I
tought it would slow things down.

I think the greatest performance benefit would have been just the
elimination of:

part1=part[1]

which wasn´t doing anything usefull anyway. :)


Test it out yourself.

Nestor



More information about the Python-list mailing list