mem-size
v1.0.0
Published
Approximate memory size of a javascript variable.
Downloads
2
Readme
mem-size
Calculates Approximate memory size of a javascript variable.
Installation
$ npm i mem-size
Usage
require('mem-size')(variable, pretty)
- Gets the approximate size of the given variable in bytes.
pretty
: if sets totrue
, returns the size in pretty format (e.g., 12.345 KB).
Supported Types
- Boolean
- Number
- String
- Object
- Array
Example
var memSize = require('mem-size');
var testNumber = 123456789;
memSize(testNumber); // 8
memSize(testNumber, true); // '8 bytes'
var testObject = {
aBoolean: true,
aString: 'The Quick Brown Fox Jumps Over The Lazy Dog',
aNumber: 123456789
};
memSize(testObject); // 142
memSize(testObject, true); // '142 +-24 bytes'
Note : In the above example, the +- value is depends on v8 Garbage Collector.
Roadmap
- Support for Buffers
- Support for Functions
- Support for Int8Array, Int16Array, Int32Array