Created
February 26, 2015 08:55
-
-
Save iluxame/4eed7672877177b02c1b to your computer and use it in GitHub Desktop.
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 time | |
>>> def test(): | |
... """Comapring concat. + vs list.extend vs +=""" | |
... x = range(10000000) | |
... y = range(10000000) | |
... x0 = time.clock() | |
... z = x + y | |
... t1 = time.clock() - x0 | |
... x1 = time.clock() | |
... x.extend(y) | |
... t2 = time.clock() - x1 | |
... x = range(10000000) | |
... y = range(10000000) | |
... x2 = time.clock() | |
... x += y | |
... t3 = time.clock() - x2 | |
... print "+ takes %s, extend takes %s, += takes %s" % (t1, t2, t3) | |
... | |
... | |
>>> test() | |
+ takes 0.13, extend takes 0.06, += takes 0.06 | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment