memory-diff
A simple object that enables recording heap memory that is consumed by some function/code and format the result.
Install
npm install --save memory-diff
Usage
Creation
const memoryDiffFn = ;const memoryDiff = ;
.start()
starts recording heap memory size.
memoryDiffstart;
.stop()
stops recording heap memory size.
memoryDiff;
.megabytes()
return the MB part in the recorded memory
console; // 3
.kilobytes()
return the KB part in the recorded memory
console; // 7
.bytes()
return the Bytes part in the recorded memory
console; // 588
.isRunning()
checks if the memoryDiff is running and hasn't been stopped
console; // false
.isStopped()
checks if the memoryDiff has been stopped
console; // true
.format(template)
formats the recorded memory using a custom or default template. The function replaces the memory size fractions placeholders in a string. Placeholders are:
%label
for the memoryDiff label.%mb
for Megabytes.%kb
for Kilobytes.%b
for Bytes.
// using the default templateconsole; // memory-test: 3 MB, 7 KB, 588 bytes // using a custom templateconst custom = '%label [%mb MB - %kb KB - %b B ]';console; // memory-test [3 MB - 7 KB - 588 B ]
.clear()
clears the memoryDiff values. Can be started again to record new values.
memoryDiffclear;console; // null
Example
const test = { memoryDiffstart; const arr = Array1000000; memoryDiff;};;console; // 'test: 8 MB, 115 KB, 56 bytes'
Build
grunt build
License
The MIT License. Full License is here