Skip to content

Instantly share code, notes, and snippets.

@iluxame
Created February 26, 2015 08:55
Show Gist options
  • Save iluxame/4eed7672877177b02c1b to your computer and use it in GitHub Desktop.
Save iluxame/4eed7672877177b02c1b to your computer and use it in GitHub Desktop.
>>> 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