Last active
May 17, 2020 10:15
-
-
Save bootjp/29cfa05235d6db1ab2bf6087b16d6e9b to your computer and use it in GitHub Desktop.
python list vs. set add and remove opration.
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 | |
sset = set() | |
arr = [] | |
def main(): | |
for _ in range(3): | |
start = time.time() | |
for i in range(50): | |
for i in range(50): | |
arr.append(i) | |
for ii in range(50): | |
if ii in arr: | |
arr.remove(ii) | |
elapsed_time = time.time() - start | |
print("list for elapsed_time:{0}".format(elapsed_time) + "[sec]") | |
start = time.time() | |
for _ in range(50): | |
for i in range(50): | |
sset.add(i) | |
for ii in range(50): | |
sset.discard(ii) | |
elapsed_time = time.time() - start | |
print("set for elapsed_time:{0}".format(elapsed_time) + "[sec]") | |
print("--") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
try 5000 loops