Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Did you know that each integer in a PHP array takes 68 bytes of storage? (pankaj-k.net)
16 points by nickb on April 1, 2008 | hide | past | favorite | 4 comments


Kinda misleading title. It's not the int, it's the int in an array. Or, more precisely, in a hash table, since PHP doesn't actually have strictly-numerically-indexed vectors.


Try opening up a python interpreter and running help(int). You'll notice something surprising -- there are over 50 methods available for ints. This ranges from all the basic math operations, shifts, boolean operations, and high precision math functions.

The actual data itself is small, either 4 or 8 bytes, depending on the architecture. Now, depending on the language php was written in (I believe it is C), the other ~60 bytes is probably has metadata associated with all the operations.


Interestingly enough, as far as I know, Python ints and floats each take up a cumulative 20 bytes.


I hardly recommend using PHP for number crunching to all of my competitors.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: