Skip to content

Instantly share code, notes, and snippets.

@shimakaze-git
Last active September 1, 2019 11:31
Show Gist options
  • Save shimakaze-git/4bfe6c494fac9f8dc9634a77fe427c59 to your computer and use it in GitHub Desktop.
Save shimakaze-git/4bfe6c494fac9f8dc9634a77fe427c59 to your computer and use it in GitHub Desktop.
リスト内包表記とlistでは確保されているメモリサイズが違う
# 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