miktam / sizeof

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

import buffer polyfill only if needed #98

Closed corradodellorusso closed 1 month ago

corradodellorusso commented 2 months ago

Buffer polyfill is considerably slower than the one built in node. When I try to get the size of the following object { a: 1, b: 2, c: 3, d: { a: 1, b: 2, c: 3, d: { a: 1, b: 2, c: 3, d: { a: 1, b: 2, c: 3 } } } } one million times (1_000_000) in node 20 it takes 1817ms with the polyfill and 1197ms without.

I'm proposing to import the polyfill only when running in browser to speed up the calculation in node environment.