Revision 1 as of 2005-05-19 16:22:08

Clear message

Counter to the performance guide on python 2.4 the following string concatenation is almost twice as fast:

Toggle line numbers
   1 # Code is Public Domain.
   2 from time import time
   3 t = time()
   4 
   5 s = 'lksdajflakjdsflku09uweoir'
   6 for x in range(40):
   7     s += s[len(s)/2:]
   8     
   9 print 'duration:', time()-t

as:

Toggle line numbers
   1 # Code is Public Domain.
   2 from time import time
   3 t = time()
   4 
   5 s = 'lksdajflakjdsflku09uweoir'
   6 for x in range(40):
   7     s = "".join((s, s[len(s)/2:]))
   8     
   9 print 'duration:', time()-t

Unable to edit the page? See the FrontPage for instructions.