re.search much slower then grep on some regular expressions
Bruno Desthuilliers
bruno.42.desthuilliers at websiteburo.invalid
Fri Jul 4 08:34:34 EDT 2008
Bruno Desthuilliers a écrit :
> Henning_Thornblad a écrit :
>> What can be the cause of the large difference between re.search and
>> grep?
>>
>> This script takes about 5 min to run on my computer:
>> #!/usr/bin/env python
>> import re
>>
>> row=""
>> for a in range(156000):
>> row+="a"
>> print re.search('[^ "=]*/',row)
>>
>>
>> While doing a simple grep:
>> grep '[^ "=]*/' input (input contains 156.000 a in
>> one row)
>> doesn't even take a second.
>>
>> Is this a bug in python?
>
> Please re-read carefully your python code. Don't you think there's a
> subtle difference between reading a file and buildin 156000 string
> objects ?
>
Mmm... This set aside, after testing it (building the string in a
somewhat more efficient way), the call to re.search effectively takes
ages to return. Please forget my previous post.
More information about the Python-list
mailing list