[prev in list] [next in list] [prev in thread] [next in thread]
List: pypy-dev
Subject: Re: [pypy-dev] [Python-Dev] efficient string concatenation (yep, from 2004)
From: Lennart Regebro <regebro () gmail ! com>
Date: 2013-02-13 7:42:17
Message-ID: CAL0kPAWk2F-AGyFmjKcwxG5_4-T8rjba+WNin+vAqhTvU+ffRA () mail ! gmail ! com
[Download RAW message or body]
> Something is needed - a patch for PyPy or for the documentation I guess.
Not arguing that it wouldn't be good, but I disagree that it is needed.
This is only an issue when you, as in your proof, have a loop that
does concatenation. This is usually when looping over a list of
strings that should be concatenated together. Doing so in a loop with
concatenation may be the natural way for people new to Python, but the
"natural" way to do it in Python is with a ''.join() call.
This:
s = ''.join(('X' for x in xrange(x)))
Is more than twice as fast in Python 2.7 than your example. It is in
fact also slower in PyPy 1.9 than Python 2.7, but only with a factor
of two:
Python 2.7:
time for 10000000 concats = 0.887
Pypy 1.9:
time for 10000000 concats = 1.600
(And of course s = 'X'* x takes only a bout a hundredth of the time,
but that's cheating. ;-)
//Lennart
_______________________________________________
pypy-dev mailing list
pypy-dev@python.org
http://mail.python.org/mailman/listinfo/pypy-dev
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic