miktam / sizeof

Get size of a JavaScript object
MIT License
301 stars 45 forks source link

bigint support ? #54

Closed Truth1984 closed 1 year ago

Truth1984 commented 3 years ago
var sizeof = require('object-sizeof');
sizeof(10n) == 0; //true
Truth1984 commented 3 years ago

Technically, your calculation is wrong.

const v8 = require("v8");
const so = require("object-sizeof");

so(2147483647) // 8
so(2147483648) // 8, wrong
so(21474836480) // 8, wrong
so("") // 0, wrong
so("A") // 2, wrong

v8.serialize("").byteLength // 4
v8.serialize(2147483647).byteLength // 8
v8.serialize(2147483648).byteLength // 11

v8.serialize(0).byteLength // 4
v8.serialize("A").byteLength // 5 ascii 4 + 1
v8.serialize("中").byteLength // 6 unicode 4 + 2
miktam commented 1 year ago

Here is what ChatGPT suggests regarding the calculating of bigint size in bytes

bigint