slow Python 3.0 write performance?

Mike Driscoll kyosohma at gmail.com
Fri Dec 5 20:27:19 CET 2008


On Dec 5, 12:54 pm, Istvan Albert <istvan.alb... at gmail.com> wrote:
> Could someone run the code below on both Python 2.5 and 3.0
>
> For me (on Windows) it runs over 7 times slower with Python 3.0
>
> import time
>
> lo, hi, step = 10**5, 10**6, 10**5
>
> # writes increasingly more lines to a file
> for N in range(lo, hi, step):
>     fp = open('foodata.txt', 'wt')
>     start = time.time()
>     for i in range( N ):
>         fp.write( '%s\n' % i)
>     fp.close()
>     stop = time.time()
>     print ( "%s\t%s" % (N, stop-start) )

Ran on Windows XP virtual machine:

3.0 output:

100000	0.889999866486
200000	1.79699993134
300000	2.875
400000	3.73399996758
500000	4.71899986267
600000	5.59400010109
700000	7.04699993134
800000	7.31299996376
900000	8.375


2.5.2 output:

100000	0.156000137329
200000	0.296999931335
300000	0.640000104904
400000	0.640000104904
500000	0.78200006485
600000	0.952999830246
700000	1.13999986649
800000	1.25
900000	1.42199993134

Slowness in this exercise is confirmed on Windows XP.

Mike



More information about the Python-list mailing list