Skip to content

Conversation

@gksalil
Copy link

@gksalil gksalil commented Mar 5, 2021

This commit will give object size too in the output

@gksalil gksalil closed this Mar 5, 2021
@gksalil gksalil reopened this Mar 5, 2021
Copy link
Owner

@mgedmin mgedmin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution!

This is definitely an interesting idea, but I dislike how it makes backwards-incompatible changes to the structure of the return value. Perhaps a second function, typestats_with_sizes() would be better?

Also, I will not merge it without documentation changes.

for name, count in stats:
file.write('%-*s %i\n' % (width, name, count))
file.write('%-*s - %i - %i - %i\n' %
(width, name, count[0], count[1], count[0]*count[1]))
Copy link
Owner

@mgedmin mgedmin Mar 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assumes all the objects of the same type are of the same size, which is not necessarily true.

On my laptop sys.getsizeof("a") == 50, but sys.getsizeof("a"*1000) == 1049.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants