diff options
author | Rich Trott <rtrott@gmail.com> | 2016-05-14 15:24:34 -0700 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2016-05-25 10:57:59 -0700 |
commit | c9a5990a76ccb15872234948e23bdc12691c2e70 (patch) | |
tree | 860e28d73ed7df27216938b3c7a808f74a45eb6b /benchmark/child_process | |
parent | 33c7b45378777ddff6dad1a74095d0d8d155f56d (diff) | |
download | node-new-c9a5990a76ccb15872234948e23bdc12691c2e70.tar.gz |
child_process: measure buffer length in bytes
This change fixes a known issue where `maxBuffer` limits by characters
rather than bytes. Benchmark added to confirm no performance regression
occurs with this change.
PR-URL: https://github.com/nodejs/node/pull/6764
Fixes: https://github.com/nodejs/node/issues/1901
Reviewed-By: Brian White <mscdex@mscdex.net>
Diffstat (limited to 'benchmark/child_process')
-rw-r--r-- | benchmark/child_process/child-process-exec-stdout.js | 30 | ||||
-rw-r--r-- | benchmark/child_process/child-process-read.js | 18 |
2 files changed, 39 insertions, 9 deletions
diff --git a/benchmark/child_process/child-process-exec-stdout.js b/benchmark/child_process/child-process-exec-stdout.js new file mode 100644 index 0000000000..79efb6fadf --- /dev/null +++ b/benchmark/child_process/child-process-exec-stdout.js @@ -0,0 +1,30 @@ +'use strict'; +const common = require('../common.js'); +const bench = common.createBenchmark(main, { + len: [64, 256, 1024, 4096, 32768], + dur: [5] +}); + +const exec = require('child_process').exec; +function main(conf) { + bench.start(); + + const dur = +conf.dur; + const len = +conf.len; + + const msg = `"${'.'.repeat(len)}"`; + msg.match(/./); + const options = {'stdio': ['ignore', 'pipe', 'ignore']}; + // NOTE: Command below assumes bash shell. + const child = exec(`while\n echo ${msg}\ndo :; done\n`, options); + + var bytes = 0; + child.stdout.on('data', function(msg) { + bytes += msg.length; + }); + + setTimeout(function() { + child.kill(); + bench.end(bytes); + }, dur * 1000); +} diff --git a/benchmark/child_process/child-process-read.js b/benchmark/child_process/child-process-read.js index c1a7474aae..33c268390f 100644 --- a/benchmark/child_process/child-process-read.js +++ b/benchmark/child_process/child-process-read.js @@ -1,20 +1,20 @@ 'use strict'; -var common = require('../common.js'); -var bench = common.createBenchmark(main, { +const common = require('../common.js'); +const bench = common.createBenchmark(main, { len: [64, 256, 1024, 4096, 32768], dur: [5] }); -var spawn = require('child_process').spawn; +const spawn = require('child_process').spawn; function main(conf) { bench.start(); - var dur = +conf.dur; - var len = +conf.len; + const dur = +conf.dur; + const len = +conf.len; - var msg = '"' + Array(len).join('.') + '"'; - var options = { 'stdio': ['ignore', 'ipc', 'ignore'] }; - var child = spawn('yes', [msg], options); + const msg = '"' + Array(len).join('.') + '"'; + const options = {'stdio': ['ignore', 'ipc', 'ignore']}; + const child = spawn('yes', [msg], options); var bytes = 0; child.on('message', function(msg) { @@ -23,7 +23,7 @@ function main(conf) { setTimeout(function() { child.kill(); - var gbits = (bytes * 8) / (1024 * 1024 * 1024); + const gbits = (bytes * 8) / (1024 * 1024 * 1024); bench.end(gbits); }, dur * 1000); } |