Last active
September 1, 2019 11:31
-
-
Save shimakaze-git/4bfe6c494fac9f8dc9634a77fe427c59 to your computer and use it in GitHub Desktop.
リスト内包表記と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
# python 3.7.3 macOS | |
import sys | |
# リスト rangeによる確保 | |
val = list(range(10)) | |
get_size = sys.getsizeof(val) | |
print(get_size) | |
# 200 | |
# リスト内包表記 | |
val = [x for x in range(10)] | |
get_size = sys.getsizeof(val) | |
print(get_size) | |
# 192 | |
val = [0, 1, 2, 3, 4, 5, 6, 7, 8 ,9] | |
get_size = sys.getsizeof(val) | |
print(get_size) | |
# 144 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment