0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/benchmark/child_process/spawn-echo.js
Joyee Cheung 3d7c82bd61 test: add test for child_process benchmark
PR-URL: https://github.com/nodejs/node/pull/12326
Ref: https://github.com/nodejs/node/issues/12068
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
2017-04-19 22:58:26 +08:00

27 lines
451 B
JavaScript

'use strict';
var common = require('../common.js');
var bench = common.createBenchmark(main, {
n: [1000]
});
var spawn = require('child_process').spawn;
function main(conf) {
var n = +conf.n;
bench.start();
go(n, n);
}
function go(n, left) {
if (--left === 0)
return bench.end(n);
var child = spawn('echo', ['hello']);
child.on('exit', function(code) {
if (code)
process.exit(code);
else
go(n, left);
});
}