Skip to content

Instantly share code, notes, and snippets.

@b0bu
Last active May 27, 2021 13:14
Show Gist options
  • Save b0bu/ff2cd7a0769292be43fbc320b9c90d50 to your computer and use it in GitHub Desktop.
Save b0bu/ff2cd7a0769292be43fbc320b9c90d50 to your computer and use it in GitHub Desktop.
array v list in python

Something I thought was super interesting

# %%
from array import array

list_of_1_million_signed_ints = list(range(0, 10**6))
array_of_1_million_signed_ints = array("I", list_of_1_million_signed_ints)

print(f"size of list in mb {list_of_1_million_signed_ints.__sizeof__() / 2**20:.2f}MiB")
print(f"size of array in mb {array_of_1_million_signed_ints.__sizeof__() / 2**20:.2f}MiB")

""" 
expected output

size of list in mb 7.63MiB
size of array in mb 3.81MiB

Using 10**9 

size of list in gb 7.45GiB
size of array in gb 3.73GiB


"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment