speeding up string.split()

Remco Gerlich scarblac at pino.selwerd.nl
Sun May 27 17:54:55 EDT 2001


Chris Green <cmg at uab.edu> wrote in comp.lang.python:
> Is there any way to speed up the following code?  Speed doesn't matter
> terribly much to me but this seems to be a fair example of what I need
> to do.
> 
> In the real data, I will be able to have a large array and use
> map rather than do it line by line but, I doubt this will change
> things much for the better.
> 
> I've tried w/ python 2 and 1.5.2 and the differences between perl and
> python remain huge ( about 5s:1s python:perl ).

"Huge". It's 4 seconds on 300,000 lines. Since this sort of thing is Perl's
special expertise, I'll admit that I think that Perl has the edge here.

But does that matter for your application? If it means a minute on each
daily run, it's not worth a Usenet thread :-)
 
> The string is +'d together for usenet purposes

Hmmmmm. Actually, what happens when you remove the '+' and replace it with a 
simple backslash? Two literals in a row may form one literal, but two
strings with a '+' need to be added together every time. I think that this
*may* make a (small) difference. Wouldn't expect it to be at all
significant.

-- 
Remco Gerlich



More information about the Python-list mailing list