[Tutor] Amazing power of Regular Expressions...

John Fouhy john at fouhy.net
Mon Nov 6 22:56:46 CET 2006


On 07/11/06, Kent Johnson <kent37 at tds.net> wrote:
> If anyone really cares which Python implementation is faster, the timeit
> module is your friend. Assertions like "would probably be faster" or
> "it's also quicker" don't hold much weight. In Python, if you want to
> know what is faster, you must test.

Hmm, what exactly is the contentious code?

Morpork:~ repton$ python -m timeit -s
's="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.-"'
'"J" in s'
1000000 loops, best of 3: 0.295 usec per loop
Morpork:~ repton$ python -m timeit -s 'import re' -s 'r =
re.compile("[0-9A-Za-z_.-]")' 'r.match("J")'
1000000 loops, best of 3: 1.16 usec per loop

-- 
John.


More information about the Tutor mailing list