News for hackers. Stuff that matters.
Re:Efficient String Concatenation in Python by teneb on Sunday December 18, 2011 @02:47PM (#3367323)

  I ran these tests using Python 2.2.1 on a 433MHz PII Celeron under FreeBSD 4.9.
Hmm. I assume that the methods discussed in the link are should still be valid for Python 3.x?
Re:Efficient String Concatenation in Python by iclelland on Sunday December 18, 2011 @04:29PM (#3367531)
Most of the methods are still valid (you'll find out that the results are definitely dated, though)

You also need to keep in mind that strings in Python 3 are Unicode-only, so much of the processing will be different. The equivalent to a Python 2.x string is called 'bytes'. It would be interesting to use this to compare string vs bytes performance under Py3k.

The one test which definitely will not work out-of-the-box is #3, for the reason above. "Character" arrays are now referred to as "byte" arrays, and you'll have to change array('c') to array('b') to get the original 8-bit behaviour, or to array('u') to use Unicode characters.

Re:Efficient String Concatenation in Python by rzzzwilson on Sunday December 18, 2011 @03:31PM (#3367405)
Due to the apparent age of the testing and changes to Python string library code since then, this should be ignored until you rerun the tests using the Python version you are using for your application.

In particular, the old assumption that a += b is _horribly_ inefficient is no longer true.

Re:Efficient String Concatenation in Python by iclelland on Sunday December 18, 2011 @04:32PM (#3367547)
I don't think that assumption has been true since Python 2.4 (released 7 years ago); it's just a persistent myth about Python performance.
Re:Efficient String Concatenation in Python by c00w on Sunday December 18, 2011 @02:50PM (#3367327)
return ''.join(`num` for num in xrange(loop_count))

is better than

return ''.join([`num` for num in xrange(loop_count)])

Re:Efficient String Concatenation in Python by rabidsnail on Sunday December 18, 2011 @03:21PM (#3367381)
The latter will allocate all of the integers and then free them as they're joined. The former will allocate one integer, then add it to the string and free it, then allocate another integer.
Re:Efficient String Concatenation in Python by joshu on Tuesday December 27, 2011 @10:34PM (#3398490)
What is with he back ticks around num?