Closed springmeyer closed 6 years ago
This could be done by:
--mem
argument to the benchmark scripts and include bytes
module
npm install bytes --save
var memstats = {
max_rss:0,
max_heap:0,
max_heap_total:0
};
--mem
is passed, then check every 100
iterations for memory peak: if (track_mem && (runs % 100) == 0) {
var mem = process.memoryUsage();
if (mem.rss > memstats.max_rss) memstats.max_rss = mem.rss;
if (mem.heapTotal > memstats.max_heap_total) memstats.max_heap_total = mem.heapTotal;
if (mem.heapUsed > memstats.max_heap) memstats.max_heap = mem.heapUsed;
}
console.log('Benchmark peak mem: ',bytes(memstats.max_rss),bytes(memstats.max_heap),bytes(memstats.max_heap_total));
Finished per https://github.com/mapbox/node-cpp-skel/pull/102
Memory usage can be as important of a target as latency when aiming for fast code. This is because an application that might run fast under low memory pressure could all of a sudden run really slow under high memory pressure.
So, it would be great to add memory tracking to the node-cpp-skel benchmarks, such that developers can opt-in easiely to seeing what the peak memory usage was during a benchmark. This should be opt-in because tracking memory might skew the code speed slightly, so developers should only enable when they absolutely need memory tracking.
TODO: define these terms in the C++ glossary: https://github.com/mapbox/cpp/issues/44