Steven D'Aprano <[email protected]> added the comment:
I'm getting similar results in Python 3.9.
[steve ~]$ python3.9 -m timeit -s "a = 'A'*10000" -s "import re"
"re.search('^x', a)"
5000 loops, best of 5: 67.3 usec per loop
[steve ~]$ python3.9 -m timeit -s "a = 'A'*100000" -s "import re"
"re.search('^x', a)"
500 loops, best of 5: 639 usec per loop
[steve ~]$ python3.9 -m timeit -s "a = 'A'*1000000" -s "import re"
"re.search('^x', a)"
50 loops, best of 5: 6.27 msec per loop
[steve ~]$ python3.9 -m timeit -s "a = 'A'*10000000" -s "import re"
"re.search('^x', a)"
5 loops, best of 5: 62.8 msec per loop
[steve ~]$ python3.9 -m timeit -s "a = 'A'*100000000" -s "import re"
"re.search('^x', a)"
1 loop, best of 5: 654 msec per loop
It looks like the time is roughly linear in the length of the string.
I get the same result as far back as Python 2.7 (I haven't tried older
versions).
[steve ~]$ python2.7 -m timeit -s "a = 'A'*10000" -s "import re"
"re.search('^x', a)"
10000 loops, best of 3: 75.7 usec per loop
[steve ~]$ python2.7 -m timeit -s "a = 'A'*10000000" -s "import re"
"re.search('^x', a)"
10 loops, best of 3: 73.4 msec per loop
I would have expected essentially constant time, as in re.match:
[steve ~]$ python3.9 -m timeit -s "a = 'A'*10000" -s "import re" "re.match('x',
a)"
500000 loops, best of 5: 560 nsec per loop
[steve ~]$ python3.9 -m timeit -s "a = 'A'*100000000" -s "import re"
"re.match('x', a)"
500000 loops, best of 5: 561 nsec per loop
----------
nosy: +steven.daprano
versions: +Python 3.9
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue42885>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com