Created
September 17, 2015 13:11
-
-
Save AoJ/1ca4a77b2e96778b28ad to your computer and use it in GitHub Desktop.
node.js memory, cpu, gc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var SlowBuffer = require('buffer').SlowBuffer; | |
var ITER = 1e5, SIZE = 65536, cntr = 0; | |
var t = process.hrtime(); | |
(function runner() { | |
if (++cntr > ITER) return print(); | |
new SlowBuffer(SIZE); | |
setImmediate(runner); | |
}()); | |
function print() { | |
t = process.hrtime(t); | |
console.log(((t[0] * 1e9 + t[1]) / ITER).toFixed(1) + ' ns/op'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var limit = 1000000; | |
var concurrent = 20; | |
var scavenges = true; | |
var warmup = limit / 10; | |
var start, count = 0; | |
limit += warmup; | |
function call() { | |
var buffer = new Buffer(64 * 1024); | |
var bufferx; | |
if (scavenges && (count % 170 === 0)) { | |
// gc(true) is a scavenge. Not sure if this is documented. | |
gc(true); | |
} | |
count++; | |
if (count > limit) { | |
console.log(process.hrtime(start)); | |
process.exit(0); | |
} else if (count === warmup) { | |
start = process.hrtime(); | |
} | |
setImmediate(call); | |
} | |
for (var i = 0; i < concurrent; i++) { | |
call(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment