""" Test by Ben Hoyt of Python string concatenation speed: join versus += see also http://www.skymind.com/~ocrow/python_string/ On my Windows XP PC using CPython 2.5.1 I get these results: ---- N = 100000 join 0.000 plus 0.047 ---- N = 200000 join 0.000 plus 0.203 ---- N = 400000 join 0.016 plus 1.016 ---- N = 800000 join 0.031 plus 4.266 ---- N = 1600000 join 0.062 plus 19.406 """ import time def plus(list): s = '' for x in list: s += x return s def join(list): return ''.join(list) for N in [100000, 200000, 400000, 800000, 1600000]: biglist = [str(i) for i in xrange(N)] print '---- N = %d' % N for f in [join, plus]: t0 = time.time() f(biglist) elapsed = time.time() - t0 print f.__name__, '%.3f' % elapsed