Help with script with performance problems

Paul Clinch pclinch at internet-glue.co.uk
Sun Nov 23 12:30:32 EST 2003


mikit at zoran.co.il (Miki Tebeka) wrote in message news:<6250403b.0311230213.124d969 at posting.google.com>...
> Hello Dennis,
> 
> A general note: Use the "hotshot" module to find where you spend most of your time.
> 
> >         splitline = string.split(line)
> My guess is that if you'll use the "re" module things will be much faster.
> 
> import re
> ws_split = re.compile("\s+").split
> ...
> splitline = split(line)
> ...
> 
> HTH.
> 
> Miki


An alternative in python 2.3 is the timeit module, the following
extracted from doc.s:-
import timeit

timer1 = timeit.Timer('unicode("abc")')
timer2 = timeit.Timer('"abc" + u""')

# Run three trials
print timer1.repeat(repeat=3, number=100000)
print timer2.repeat(repeat=3, number=100000)

# On my laptop this outputs:
# [0.36831796169281006, 0.37441694736480713, 0.35304892063140869]
# [0.17574405670166016, 0.18193507194519043, 0.17565798759460449]

Regards Paul Clinch




More information about the Python-list mailing list