[pypy-issue] [issue1622] string replace is slower in pypy vs cpython

Juan Orlandini tracker at bugs.pypy.org
Wed Oct 16 21:18:23 CEST 2013


New submission from Juan Orlandini <tachijuan at gmail.com>:

When you run this:

import timeit
timeit.repeat(stmt='"
{0:08b}".format(int("123")).translate(string.maketrans("01","-*"))',setup='import 
string', number=1000000,repeat = 5)

The run time for PyPy is slower than CPython.

On a MacBook Air (5,2), the timeit output is:

PyPy: [4.286413908004761, 4.306797981262207, 4.228583097457886, 4.298407077789307, 
4.2970991134643555]
CPython: [2.817600965499878, 2.7548630237579346, 2.7212469577789307, 
2.7562379837036133, 2.761147975921631]

The equivalent expression:
timeit.repeat(stmt='"{0:08b}".format(int("123")).replace("1","*").replace("0","-
")',setup='', number=1000000,repeat = 5)

is faster on PyPy vs CPython:

PyPy: [0.5421171188354492, 0.536733865737915, 0.534991979598999, 
0.5270521640777588, 0.5374889373779297]
CPython: [2.2817749977111816, 2.288715124130249, 2.287511110305786, 
2.295119047164917, 2.2907910346984863]

Which is what I expected.

----------
messages: 6272
nosy: pypy-issue, tachijuan
priority: performance bug
release: 2.1
status: unread
title: string replace is slower in pypy vs cpython

________________________________________
PyPy bug tracker <tracker at bugs.pypy.org>
<https://bugs.pypy.org/issue1622>
________________________________________


More information about the pypy-issue mailing list