
• #2
This might be some help: http://www.espruino.com/Performance#everydatatypeinespruinoisbasedonasinglestorageunit1216bytes
But as you spotted, blocksize is 14, so each block is 14 bytes. So
E.getSizeOf(Number.MAX_VALUE)
being 1 means that single number takes up 14 bytes.Other examples:
E.getSizeOf({}) == 1 // an object takes 1 var E.getSizeOf({a:42}) == 2 // small numbers can fit inside the variable name E.getSizeOf({a:1,b:2,c:3,d:4}) == 5 // small names + numbers packed together take 1 var each (+1 for the object) E.getSizeOf({a:123456}) == 3 // big numbers take more E.getSizeOf({a_really_big_var_name:123456}) == 5 // big variable names take more as well
Reference page says that "E.getSizeOf() returns the number of variable blocks used by the supplied variable".
But how should I estimate the real size of entities in my app? For example, E.getSizeOf(Number.MAX_VALUE) returns 1, meanwhile the bocksize is 14 (according to process.memory) and espruino numbers are 64bit. It just makes no sense for me.
Sorry for asking kind of stupid question, but I really want to figure out how to calculate size of objects as preciese as possible. Thanks for answer in advance!