-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
child_process: fix deoptimizing use of arguments
Remove use of arguments in normalizeExecArgs() and normalizeSpawnArguments(). Refs: #10323 PR-URL: #11535 Backport-PR-URL: #13752 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
- Loading branch information
1 parent
b483675
commit 327f11f
Showing
2 changed files
with
155 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
'use strict'; | ||
|
||
const common = require('../common.js'); | ||
const cp = require('child_process'); | ||
|
||
const command = 'echo'; | ||
const args = ['hello']; | ||
const options = {}; | ||
const cb = () => {}; | ||
|
||
const configs = { | ||
n: [1e3], | ||
methodName: [ | ||
'exec', 'execSync', | ||
'execFile', 'execFileSync', | ||
'spawn', 'spawnSync', | ||
], | ||
params: [1, 2, 3, 4], | ||
}; | ||
|
||
const bench = common.createBenchmark(main, configs); | ||
|
||
function main(conf) { | ||
const n = +conf.n; | ||
const methodName = conf.methodName; | ||
const params = +conf.params; | ||
|
||
const method = cp[methodName]; | ||
|
||
switch (methodName) { | ||
case 'exec': | ||
switch (params) { | ||
case 1: | ||
bench.start(); | ||
for (let i = 0; i < n; i++) method(command).kill(); | ||
bench.end(n); | ||
break; | ||
case 2: | ||
bench.start(); | ||
for (let i = 0; i < n; i++) method(command, options).kill(); | ||
bench.end(n); | ||
break; | ||
case 3: | ||
bench.start(); | ||
for (let i = 0; i < n; i++) method(command, options, cb).kill(); | ||
bench.end(n); | ||
break; | ||
} | ||
break; | ||
case 'execSync': | ||
switch (params) { | ||
case 1: | ||
bench.start(); | ||
for (let i = 0; i < n; i++) method(command); | ||
bench.end(n); | ||
break; | ||
case 2: | ||
bench.start(); | ||
for (let i = 0; i < n; i++) method(command, options); | ||
bench.end(n); | ||
break; | ||
} | ||
break; | ||
case 'execFile': | ||
switch (params) { | ||
case 1: | ||
bench.start(); | ||
for (let i = 0; i < n; i++) method(command).kill(); | ||
bench.end(n); | ||
break; | ||
case 2: | ||
bench.start(); | ||
for (let i = 0; i < n; i++) method(command, args).kill(); | ||
bench.end(n); | ||
break; | ||
case 3: | ||
bench.start(); | ||
for (let i = 0; i < n; i++) method(command, args, options).kill(); | ||
bench.end(n); | ||
break; | ||
case 4: | ||
bench.start(); | ||
for (let i = 0; i < n; i++) method(command, args, options, cb).kill(); | ||
bench.end(n); | ||
break; | ||
} | ||
break; | ||
case 'execFileSync': | ||
switch (params) { | ||
case 1: | ||
bench.start(); | ||
for (let i = 0; i < n; i++) method(command); | ||
bench.end(n); | ||
break; | ||
case 2: | ||
bench.start(); | ||
for (let i = 0; i < n; i++) method(command, args); | ||
bench.end(n); | ||
break; | ||
case 3: | ||
bench.start(); | ||
for (let i = 0; i < n; i++) method(command, args, options); | ||
bench.end(n); | ||
break; | ||
} | ||
break; | ||
case 'spawn': | ||
switch (params) { | ||
case 1: | ||
bench.start(); | ||
for (let i = 0; i < n; i++) method(command).kill(); | ||
bench.end(n); | ||
break; | ||
case 2: | ||
bench.start(); | ||
for (let i = 0; i < n; i++) method(command, args).kill(); | ||
bench.end(n); | ||
break; | ||
case 3: | ||
bench.start(); | ||
for (let i = 0; i < n; i++) method(command, args, options).kill(); | ||
bench.end(n); | ||
break; | ||
} | ||
break; | ||
case 'spawnSync': | ||
switch (params) { | ||
case 1: | ||
bench.start(); | ||
for (let i = 0; i < n; i++) method(command); | ||
bench.end(n); | ||
break; | ||
case 2: | ||
bench.start(); | ||
for (let i = 0; i < n; i++) method(command, args); | ||
bench.end(n); | ||
break; | ||
case 3: | ||
bench.start(); | ||
for (let i = 0; i < n; i++) method(command, args, options); | ||
bench.end(n); | ||
break; | ||
} | ||
break; | ||
} | ||
} |
This file contains 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