Python deep getsizeof list with contents?

后端 未结 5 1871
[愿得一人]
[愿得一人] 2020-12-01 10:44

I was surprised that sys.getsizeof( 10000*[x] ) is 40036 regardless of x: 0, \"a\", 1000*\"a\", {}.
Is there a deep_getsizeof which properly co

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-01 11:30

    I wrote a tool called RememberMe exactly for this. Basic usage:

    from rememberme import memory
    a = [1, 2, 3]
    b = [a, a, a]
    print(memory(a))  # 172 bytes
    print(memory(b))  # 260 bytes. Duplication counted only once.
    

    Hope it helps.

提交回复
热议问题