how to avoid leading white spaces
Thorsten Kampe
thorsten at thorstenkampe.de
Fri Jun 3 04:32:12 EDT 2011
* Roy Smith (Thu, 02 Jun 2011 21:57:16 -0400)
> In article <94ph22FrhvU5 at mid.individual.net>,
> Neil Cerutti <neilc at norwich.edu> wrote:
> > On 2011-06-01, rurpy at yahoo.com <rurpy at yahoo.com> wrote:
> > > For some odd reason (perhaps because they are used a lot in
> > > Perl), this groups seems to have a great aversion to regular
> > > expressions. Too bad because this is a typical problem where
> > > their use is the best solution.
> >
> > Python's str methods, when they're sufficent, are usually more
> > efficient.
>
> I was all set to say, "prove it!" when I decided to try an experiment.
> Much to my surprise, for at least one common case, this is indeed
> correct.
> [...]
> t1 = timeit.Timer("'laoreet' in text",
> "text = '%s'" % text)
> t2 = timeit.Timer("pattern.search(text)",
> "import re; pattern = re.compile('laoreet'); text =
> '%s'" % text)
> print t1.timeit()
> print t2.timeit()
> -------------------------------------------------
> ./contains.py
> 0.990975856781
> 1.91417002678
> -------------------------------------------------
Strange that a lot of people (still) automatically associate
"efficiency" with "takes two seconds to run instead of one" (which I
guess no one really cares about).
Efficiency is much better measured in which time it saves you to write
and maintain the code in a readable way.
Thorsten
More information about the Python-list
mailing list