You should gather your lines in a list and write a bigger amount of
data (or even all data) at one time.
Because the I/O is blocking your program execution you get poor
performance.
You could also write until your buffer reaches 1000 lines, 10000, etc.
and then clear
the list if memory consumption is a issue.

Try this:

buffer = []

# just another performance optimization, because the lookup of the
# append method of the list object takes some time on each iteration
step
append = buffer.append

for i in range(numberOfHairs):
    for j in range (numberOfPoints):
        append("\t\t%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f
\n" % (
             A[j][0], A[j][1], A[j][2], B[j][0]-A[j][0], B[j][1]-A[j]
[1],
             B[j][2]-A[j][2], C[j], D[j][0], D[j][1], D[j][2])
        )
f.write( "".join(buffer) )
f.close()

On 15 Okt., 17:12, Horvátth Szabolcs <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I'm doing some data exporting using a python scripted plugin command and
> found the file output being very slow.
> In a specific case the file write took 90 seconds and when I commented
> the f.write() stuff (so the command only did the queries) it dropped to
> 15 seconds.
> This is the structure of the write part:
>
> for i in range(numberOfHairs):
> ...
>     for j in range (numberOfPoints):
>        ...
>         f.write("\t\t%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f
> %.3f\n" % (A[j][0], A[j][1], A[j][2], B[j][0]-A[j][0], B[j][1]-A[j][1],
> B[j][2]-A[j][2], C[j], D[j][0], D[j][1], D[j][2]))
> f.close()
>
> Am I doing completely wrong? What can I do to speed up ascii file writing?
>
> Cheers,
> Szabolcs

--~--~---------~--~----~------------~-------~--~----~
Yours,
Maya-Python Club Team.
-~----------~----~----~----~------~----~------~--~---

Reply via email to