Question on periods in strings

John Yeung gallium.arsenide at gmail.com
Thu Mar 12 00:42:26 EDT 2009


On Mar 11, 9:42 pm, "Philip Bloom" <pbl... at crystald.com> wrote:
> #test A
> #runs in 5.8 seconds.
> from datetime import datetime
> testvar2='9a00'
> startTime = datetime.now()
> filehandle=open('testwriting.txt','w')
> for var in range(10000000):
>     filehandle.write(testvar2)
> filehandle.close()
> print (datetime.now() - startTime)
>
> #test B
> #runs in 10.9 seconds.
> from datetime import datetime
> testvar2='9.00'
> startTime = datetime.now()
> filehandle=open('testwriting.txt','w')
> for var in range(10000000):
>     filehandle.write(testvar2)
> filehandle.close()
> print (datetime.now() - startTime)

Your results are fascinating and utterly bizarre.  I cannot reproduce
them.  I copied and pasted your code and ran as a single program on
Python 2.6.1 on my WinXP machine.  After several trials, the first
print always showed about 4.8 seconds and the second always about 4.6
seconds.  Transposing test A and B resulted in the first print (now
test B) showing 4.8 and the second print 4.6.

John



More information about the Python-list mailing list