Most efficient way of storing 1024*1024 bits

Alex Martelli aleax at mail.comcast.net
Wed Nov 2 10:33:30 EST 2005


Paul Rubin <http://phr.cx@NOSPAM.invalid> wrote:
   ...
> You can use re.search on array.array byte vectors.  I don't know how
> the speed compares with string.find.

Pretty well, though of course one should measure on representative cases
for one's specific application needs:

Helen:~ alex$ python -mtimeit -s'import re, array' -s'x=999999*"x"'
-s'x=x+"a"+x' \
> 'x.find("a")'
100 loops, best of 3: 13.3 msec per loop

Helen:~ alex$ python -mtimeit -s'import re, array' -s'x=999999*"x"'
-s'x=x+"a"+x' 're.search("a", x)'
100 loops, best of 3: 8.73 msec per loop

Helen:~ alex$ python -mtimeit -s'import re, array' -s'x=999999*"x"'
-s'x=x+"a"+x' -s'x=array.array("c",x)' 're.search("a", x)'
100 loops, best of 3: 8.72 msec per loop


Alex



More information about the Python-list mailing list