Nick Craig-Wood wrote:
>> #!/usr/bin/env python
>> import re
>> r = re.compile(r'destroy', re.IGNORECASE)
>>
>> for s in file('bigfile'):
>>if r.search(s): print s.rstrip("\r\n")
footnote: if you're searching for literal strings with Python 2.5, using "in"
is a
lot faster than using re.s
js a écrit :
> Just my curiosity.
> Can python beats perl at speed of grep-like processing?
Probably not.
>
> $ wget http://www.gutenberg.org/files/7999/7999-h.zip
> $ unzip 7999-h.zip
> $ cd 7999-h
> $ cat *.htm > bigfile
> $ du -h bigfile
> du -h bigfile
> 8.2Mbigfile
>
> -- grep.
js <[EMAIL PROTECTED]> wrote:
> Just my curiosity.
> Can python beats perl at speed of grep-like processing?
>
> $ wget http://www.gutenberg.org/files/7999/7999-h.zip
> $ unzip 7999-h.zip
> $ cd 7999-h
> $ cat *.htm > bigfile
> $ du -h bigfile
> du -h bigfile
> 8.2M bigfile
>
> #!/usr/l
In <[EMAIL PROTECTED]>, Tim Smith
wrote:
> also, if you replace the regex with a test like lambda x:
> x.lower().find("destroy") != -1, you will get really close to the speed
> of perl's
Testing for ``'destroy' in x.lower()`` should even be a little bit faster.
Ciao,
Marc 'BlackJack' Rin
you may not be able to beat perl's regex speed, but you can take some steps to
speed up your python program using map and filter
here's a modified python program that will do your search faster
#!/usr/bin/env python
import re
r = re.compile(r'destroy', re.IGNORECASE)
def stripit(x):
return
js wrote:
> Just my curiosity.
> Can python beats perl at speed of grep-like processing?
>
>
> $ wget http://www.gutenberg.org/files/7999/7999-h.zip
> $ unzip 7999-h.zip
> $ cd 7999-h
> $ cat *.htm > bigfile
> $ du -h bigfile
> du -h bigfile
> 8.2M bigfile
>
> -- grep.pl --
>
Just my curiosity.
Can python beats perl at speed of grep-like processing?
$ wget http://www.gutenberg.org/files/7999/7999-h.zip
$ unzip 7999-h.zip
$ cd 7999-h
$ cat *.htm > bigfile
$ du -h bigfile
du -h bigfile
8.2Mbigfile
-- grep.pl --
#!/usr/local/bin/perl
open(F, 'bigfile