Skip to content

Instantly share code, notes, and snippets.

@ccc-larc
Created November 30, 2013 09:42
Show Gist options
  • Save ccc-larc/7717083 to your computer and use it in GitHub Desktop.
Save ccc-larc/7717083 to your computer and use it in GitHub Desktop.
join v.s. +=
import timeit
#STRING = 'addddddeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeewweeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeffffffffffffffffffffffffffffffffffffffffffffffffffffffffeeeeeeeeeeeeeeeeeeeeeeeeeerwerwerwerwetrwegfsghklujsahdflkiuahfgluhewihrlwelfhlwuhfawhrgfiuhagrliwrwreqwerqwerwefsdfasdfasdfasdfdsfddddddddddddddddeeeeeeeewwwwwwwwwwwwwddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd'
STRING = 'sss'
LOOP = 1000000
TIMEIT_REPEAT = 30
def test_join():
data = []
for i in range(LOOP):
data.append(STRING)
return ''.join(data)
def test_connect():
data = ""
for i in range(LOOP):
data += STRING
return data
print 'join :', timeit.timeit(test_join, number=TIMEIT_REPEAT)
print ' += :', timeit.timeit(test_connect, number=TIMEIT_REPEAT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment