[Python] asizeof appears to be inaccurate

Discussão em 'Python' iniciado por Stack, Dezembro 8, 2024.

  1. Stack

    Stack Membro Participativo

    Take this MWE:

    from pympler import asizeof
    from random import randint, choice
    from string import printable
    from heapq import heappush
    ascii = printable[:-5]
    pq = []
    for _ in range(10000000):
    heappush(pq, (randint(0, 31), randint(0, 31), randint(0, 31), ''.join(choice(ascii) for _ in range(16)))
    print(asizeof.asizeof(pq))


    I can see from running 'top' that this takes about 2.6GB of RAM. But asizeof reports 1,449,096,184 bytes which is a long way off.

    Am I using it wrong?

    Continue reading...

Compartilhe esta Página