Question on periods in strings

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Mar 11 21:16:38 EDT 2009


En Wed, 11 Mar 2009 22:35:22 -0200, Philip Bloom <pbloom at crystald.com>  
escribió:

> Hello, this is my first time posting to the list, but my curiosity here
> is great.

Welcome!

> I was randomly toying with file writes and I ran into something that
> seemed quite odd to me.  When a period is in a string, file write takes
> about double the time.  I saw similar things with newlines, but I
> figured that was because it was doing a lookup on the escape-d n.  All
> other symbols seem to not have this problem, so I'm curious what's
> special about periods that they take so much longer to write to file.

I doubt the period is actually the culprit. There are lots of other  
variables - like disk and memory fragmentation, cpu load, ...
You omitted part of your code: do you use the same filename on both tests?  
(Note that starting with an empty file is not the same as using a  
preallocated file).
Also, do you always run both scripts in the same order? (maybe "the  
second" always runs faster, no matter which one is it).
Also note that you're measuring the time to allocate a list containing ten  
million integer objects (the range() call). xrange is a less perturbing  
option.

-- 
Gabriel Genellina




More information about the Python-list mailing list