Created
December 15, 2017 19:39
-
-
Save davidwtbuxton/9bb3b081b39744aa47842f0a45034b46 to your computer and use it in GitHub Desktop.
Ways of copying a list in Python 2.7
This file contains hidden or 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
$ python -m timeit -s 'seq = list(range(10))' '[o for o in seq]' | |
1000000 loops, best of 3: 1.75 usec per loop | |
$ python -m timeit -s 'seq = list(range(100))' '[o for o in seq]' | |
100000 loops, best of 3: 13.2 usec per loop | |
$ python -m timeit -s 'seq = list(range(1000))' '[o for o in seq]' | |
10000 loops, best of 3: 115 usec per loop | |
$ python -m timeit -s 'seq = list(range(10))' 'list(seq)' | |
1000000 loops, best of 3: 0.372 usec per loop | |
$ python -m timeit -s 'seq = list(range(100))' 'list(seq)' | |
1000000 loops, best of 3: 0.609 usec per loop | |
$ python -m timeit -s 'seq = list(range(1000))' 'list(seq)' | |
100000 loops, best of 3: 2.71 usec per loop | |
$ python --version | |
Python 2.7.14 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment