Fastest technique for string concatenation

Emile van Sebille emile at fenx.com
Sat Oct 2 15:48:01 EDT 2010


On 10/2/2010 12:09 PM python at bdurham.com said...

Your times will improve when not burdened by the repeated method lookups 
and element-wise list creation:

try with eg,

def testListAppend2():
     output = list()
     append = output.append
     for char in source:
         append( char )
     output = ''.join( output )

and even further with

def testListAppend3():
     output = list(source)
     output = ''.join( output )

Same with:

def testStringIO2():
     output = cStringIO.StringIO()
     write = output.write
     for char in source:
         write( char )
     output = output.getvalue()

Emile





More information about the Python-list mailing list