3 ms·
It seems almost all the time node.js runs hello world is spent loading its own modules. You should try something like this: // watch.js var file = proc
by DiThi 9y ago
It seems almost all the time node.js runs hello world is spent loading its own modules. You should try something like this:
// watch.js
var file = process.argv[2]
console.log('press enter to run '+file)
process.stdin.on('data', function(){
var [s1,ns1] = process.hrtime()
for(var k in require.cache) {
delete require.cache[k]
}
require(file)
var [s2,ns2] = process.hrtime()
var s = (s2-s1)+(ns2-ns1)*1e-9
console.log('time: ' + s.toFixed(9))
})
Result: less than 1ms on first run
$ node watch.js ./test.js
press enter to run ./test.js
hello world
time: 0.000952656
hello world
time: 0.000284171
edit: script now deletes all cache, not only the passed script (result is the same if the script doesn't require others)
- exikyut 9y agoHmm, very interesting. Something to definitely keep in mind, thanks.