[pypy-issue] Issue #2249: re.sub() is 5 times slower than with CPython (pypy/pypy)

Amaury Forgeot d'Arc issues-reply at bitbucket.org
Thu Mar 3 07:53:06 EST 2016


New issue 2249: re.sub() is 5 times slower than with CPython
https://bitbucket.org/pypy/pypy/issues/2249/resub-is-5-times-slower-than-with-cpython

Amaury Forgeot d'Arc:

The script below is 5 times slower with PyPy than with CPython.
I suspect the code could be optimized by using a StringBuilder instead of 
`space.call_method( w_emptystr, 'join', space.newlist(sublist_w))`

```
#!python

import re, time
regexp = re.compile('x')
s = 'x' * 1024 * 1024 * 10

def f():
  for x in xrange(10):
    t0 = time.time()
    assert len(regexp.sub('y', s)) == len(s)
    print time.time() - t0

f()

```




More information about the pypy-issue mailing list