Last active
December 20, 2015 14:59
-
-
Save yipyip/6150627 to your computer and use it in GitHub Desktop.
string concatenation timings
(Man beachte auch das letzte Ergebnis, da ist etwas Overhead beim Aufruf drin.)
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
In [41]: s = [str(i) for i in xrange(100)] | |
In [42]: timeit reduce(lambda x, y: x + y, s, '') | |
10000 loops, best of 3: 31.9 us per loop | |
In [43]: timeit "".join(s) | |
100000 loops, best of 3: 2.98 us per loop | |
In [44]: a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p = s[:16] | |
In [45]: timeit a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p | |
1000000 loops, best of 3: 1.59 us per loop | |
In [46]: timeit "".join((a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)) | |
1000000 loops, best of 3: 1.24 us per loop | |
In [47]: timeit a+b+c | |
1000000 loops, best of 3: 300 ns per loop | |
In [48]: timeit ''.join((a, b, c)) | |
1000000 loops, best of 3: 495 ns per loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment