Created
April 29, 2020 15:52
-
-
Save WhiteRobe/9ce5f1e6edd2b46b8f8066429aee3dc6 to your computer and use it in GitHub Desktop.
dequeue和list的效率比对
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, collections | |
start = time.perf_counter() | |
a = [] | |
for i in range(10000000): | |
a.insert(0, 0);a.pop(0) | |
print(time.perf_counter() - start) | |
start = time.perf_counter() | |
a = collections.deque([]) | |
for i in range(10000000): | |
a.insert(0, 0);a.pop() | |
print(time.perf_counter() - start) | |
start = time.perf_counter() | |
a = [] | |
for i in range(10000000): | |
a += [0] | |
print(time.perf_counter() - start) | |
start = time.perf_counter() | |
a = [] | |
for i in range(10000000): | |
a.append(0) | |
print(time.perf_counter() - start) | |
start = time.perf_counter() | |
a = collections.deque([]) | |
for i in range(10000000): | |
a.append(0) | |
print(time.perf_counter() - start) | |
""" | |
Output: | |
5.4079986 | |
2.2909950000000006 | |
1.7664375999999988 | |
1.3421816 | |
1.332309200000001 | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment