Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use commas for big numbers #27

Open
cool-RR opened this issue Jan 22, 2021 · 5 comments
Open

Use commas for big numbers #27

cool-RR opened this issue Jan 22, 2021 · 5 comments

Comments

@cool-RR
Copy link

cool-RR commented Jan 22, 2021

This is my dump from Heapy:

Partition of a set of 1235525 objects. Total size = 153363236 bytes.
 Index  Count   %     Size   % Cumulative  % Kind (class / dict of class)
     0 260111  21 34847420  23  34847420  23 str
     1  82607   7 16193248  11  51040668  33 dict (no owner)
     2 102994   8 14936792  10  65977460  43 bytes
     3 189724  15 14334888   9  80312348  52 tuple
     4  73463   6  9990968   7  90303316  59 function
     5  48013   4  8660794   6  98964110  65 types.CodeType
     6  64567   5  5171896   3 104136006  68 list
     7   4888   0  4896088   3 109032094  71 type
     8   2817   0  4368312   3 113400406  74 dict of module
     9   4888   0  2434624   2 115835030  76 dict of type
<1421 more rows. Type e.g. '_.more' to view.>

Numbers like 153363236 bytes are difficult to read. 153,363,236 bytes would be easier.

@zhuyifei1999
Copy link
Owner

Hmm... my main concern is if people will do numeric operations on these numbers, and it'll be troublesome to copy & paste. Maybe I'll just do the comma separation for repr output and assume that people will know we provide APIs for numeric access if they need it (this needs to be better documented... I'll add to README):

>>> h = guppy.hpy().heap()
>>> h
Partition of a set of 36625 objects. Total size = 4257226 bytes.
 Index  Count   %     Size   % Cumulative  % Kind (class / dict of class)
     0  10383  28   917674  22    917674  22 str
     1   9111  25   738760  17   1656434  39 tuple
     2   2384   7   344688   8   2001122  47 types.CodeType
     3   4766  13   336076   8   2337198  55 bytes
     4    441   1   335296   8   2672494  63 type
     5   2205   6   317520   7   2990014  70 function
     6    441   1   247080   6   3237094  76 dict of type
     7     96   0   171952   4   3409046  80 dict of module
     8    240   1   116256   3   3525302  83 dict (no owner)
     9   1090   3    95920   2   3621222  85 types.WrapperDescriptorType
<114 more rows. Type e.g. '_.more' to view.>
>>> len(h)
124
>>> h.count
36625
>>> h.size
4257226
>>> h[0].count
10383
>>> h[0].size
917674

@zhuyifei1999
Copy link
Owner

>>> __import__('guppy').hpy().heap()
Partition of a set of 36,633 objects. Total size = 4,257,677 bytes.
 Index   Count   %       Size   %   Cumulative  % Kind (class / dict of class)
     0  10,391  28    917,969  22     917,969  22 str
     1   9,111  25    738,864  17   1,656,833  39 tuple
     2   2,384   7    344,688   8   2,001,521  47 types.CodeType
     3   4,764  13    336,008   8   2,337,529  55 bytes
     4     441   1    335,296   8   2,672,825  63 type
     5   2,205   6    317,520   7   2,990,345  70 function
     6     441   1    247,080   6   3,237,425  76 dict of type
     7      96   0    171,952   4   3,409,377  80 dict of module
     8     240   1    116,256   3   3,525,633  83 dict (no owner)
     9   1,090   3     95,920   2   3,621,553  85 types.WrapperDescriptorType
<114 more rows. Type e.g. '_.more' to view.>
>>> _.byid
Set of 36,633 <mixed> objects. Total size = 4,257,677 bytes.
 Index      Size   %     Cumulative  %   Brief
     0    18,536   0.4      18,536   0.4 dict of module: os
     1     9,328   0.2      27,864   0.7 dict (no owner): 0x7f50d11fb410*323
     2     9,328   0.2      37,192   0.9 dict (no owner): 0x7f50d129beb0*291
     3     9,328   0.2      46,520   1.1 dict of module: posix
     4     8,424   0.2      54,944   1.3 set: 0x7f50d1176050
     5     8,424   0.2      63,368   1.5 set: 0x7f50d11d79b0
     6     8,424   0.2      71,792   1.7 set: 0x7f50d11d7d70
     7     8,424   0.2      80,216   1.9 set: 0x7f50d1254320
     8     8,424   0.2      88,640   2.1 set: 0x7f50d1254c80
     9     7,423   0.2      96,063   2.3 str: 'The class Bi... copy of S.\n'
<36,623 more rows. Type e.g. '_.more' to view.>

Looks decent until

>>> a = list(range(10000000))
>>> __import__('guppy').hpy().heap()
Partition of a set of 10,039,006 objects. Total size = 374,516,749 bytes.
 Index   Count   %       Size   %   Cumulative  % Kind (class / dict of class)
     0 10,000,926 100 280,028,720  75 280,028,720  75 int
     1     100   0 90,019,536  24 370,048,256  99 list
     2  10,989   0    959,949   0 371,008,205  99 str
     3   9,968   0    807,992   0 371,816,197  99 tuple
     4   2,631   0    380,360   0 372,196,557  99 types.CodeType
     5     476   0    372,536   0 372,569,093  99 type
     6   5,236   0    364,636   0 372,933,729 100 bytes
     7   2,382   0    343,008   0 373,276,737 100 function
     8     476   0    262,016   0 373,538,753 100 dict of type
     9      97   0    174,240   0 373,712,993 100 dict of module
<114 more rows. Type e.g. '_.more' to view.>
>>> _.byid
Set of 10,039,006 <mixed> objects. Total size = 374,516,749 bytes.
 Index      Size   %     Cumulative  %   Brief
     0 90,000,120  24.0  90,000,120  24.0 list: 0x7f50d0cb5cd0*10000000
     1    18,536   0.0  90,018,656  24.0 dict of module: os
     2     9,328   0.0  90,027,984  24.0 dict (no owner): 0x7f50d11fb410*323
     3     9,328   0.0  90,037,312  24.0 dict (no owner): 0x7f50d129beb0*291
     4     9,328   0.0  90,046,640  24.0 dict of module: posix
     5     8,424   0.0  90,055,064  24.0 set: 0x7f50d1176050
     6     8,424   0.0  90,063,488  24.0 set: 0x7f50d11d79b0
     7     8,424   0.0  90,071,912  24.1 set: 0x7f50d11d7d70
     8     8,424   0.0  90,080,336  24.1 set: 0x7f50d1254320
     9     8,424   0.0  90,088,760  24.1 set: 0x7f50d1254c80
<10,038,996 more rows. Type e.g. '_.more' to view.>

Goes wild. Maybe I should write some code to align the table.

@cool-RR
Copy link
Author

cool-RR commented Jan 23, 2021

I understand.

@svenil
Copy link

svenil commented Jan 23, 2021

Good idea and work. Is there an error in the count? Set of 10,039,006 vs 10,038,996 more rows

@zhuyifei1999
Copy link
Owner

Good idea and work. Is there an error in the count? Set of 10,039,006 vs 10,038,996 more rows

No ;) 10039006 - 10038996 = 10, 10 rows already displayed :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants