Closed
Description
(extracted from #3429 because that's specifically about the disparity between stdin and spawn)
This graph shows the performance of cat file | node readStdin.js
on different node.js versions on OS X 10.11:
This was generated from 11 runs of the following program after cat/piping a 1GB file generated with head -c 1000000000 /dev/zero > file
:
stdinPipe(function(err, time) {
if (err) return console.error(err.stack || err)
console.log([process.version, time].join(','))
})
function stdinPipe(cb) {
var bytesRead = 0
var time = process.hrtime()
process.stdin.resume()
process.stdin.on('data', function(data) {
bytesRead += data.length
})
process.stdin.on('error', cb)
process.stdin.on('end', function() {
if (bytesRead != 1000000000) return cb(new Error('Incorrect bytes read: ' + bytesRead))
var diff = process.hrtime(time)
cb(null, 1000 / (diff[0] + diff[1] / 1e9))
})
}
Now interestingly, as far as I can tell this seems to be a specifically pipe-related problem, because if the same program is run with node readStdin.js < file
, no such difference exists: