Created
November 30, 2013 09:42
-
-
Save ccc-larc/7717083 to your computer and use it in GitHub Desktop.
join v.s. +=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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