Created
May 6, 2016 02:03
-
-
Save mark-adams/189a7f01e1de717ef3e81b671fd69e60 to your computer and use it in GitHub Desktop.
List ordering performance comparison
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
def test_1(): | |
buf = [] | |
for i in range(1000): | |
buf.append(i) | |
buf.reverse() | |
if __name__ == '__main__': | |
import timeit | |
print('Testing with append then reverse') | |
print(timeit.timeit("test_1()", setup="from __main__ import test_1")) |
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
def test_2(): | |
buf = [] | |
for i in range(1000): | |
buf.insert(i, 0) | |
if __name__ == '__main__': | |
import timeit | |
print('Testing with prepend (via list.insert)') | |
print(timeit.timeit("test_2()", setup="from __main__ import test_2")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Results: