benchmark: support URL inputs in create-clientrequest
This patch adds the option in the create-clientrequest benchmark to accept URL inputs (as strings or as URL objects) so we can measure the impact of URL parsing in a more sophisticated use case. PR-URL: https://github.com/nodejs/node/pull/24302 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
a365bb9cb1
commit
8450d11292
@ -2,19 +2,49 @@
|
|||||||
|
|
||||||
const common = require('../common.js');
|
const common = require('../common.js');
|
||||||
const ClientRequest = require('http').ClientRequest;
|
const ClientRequest = require('http').ClientRequest;
|
||||||
|
const types = Object.keys(common.urls)
|
||||||
|
.filter((i) => common.urls[i]
|
||||||
|
.startsWith('http://'));
|
||||||
const bench = common.createBenchmark(main, {
|
const bench = common.createBenchmark(main, {
|
||||||
len: [1, 8, 16, 32, 64, 128],
|
// Use 'url' to avoid name clash with other http benchmark
|
||||||
n: [1e6]
|
url: types.concat(['wpt']),
|
||||||
|
arg: ['URL', 'string', 'options'],
|
||||||
|
e: [1]
|
||||||
});
|
});
|
||||||
|
|
||||||
function main({ len, n }) {
|
function noop() {}
|
||||||
const path = '/'.repeat(len);
|
|
||||||
const opts = { path: path, createConnection: function() {} };
|
|
||||||
|
|
||||||
bench.start();
|
function main({ url: type, arg, e }) {
|
||||||
for (var i = 0; i < n; i++) {
|
e = +e;
|
||||||
new ClientRequest(opts);
|
const data = common.bakeUrlData(type, e, false, false)
|
||||||
|
.filter((i) => i.startsWith('http://'));
|
||||||
|
const len = data.length;
|
||||||
|
var result;
|
||||||
|
var i;
|
||||||
|
if (arg === 'options') {
|
||||||
|
const options = data.map((i) => ({
|
||||||
|
path: new URL(i).path, createConnection: noop
|
||||||
|
}));
|
||||||
|
bench.start();
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
|
result = new ClientRequest(options[i]);
|
||||||
|
}
|
||||||
|
bench.end(len);
|
||||||
|
} else if (arg === 'URL') {
|
||||||
|
const options = data.map((i) => new URL(i));
|
||||||
|
bench.start();
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
|
result = new ClientRequest(options[i], { createConnection: noop });
|
||||||
|
}
|
||||||
|
bench.end(len);
|
||||||
|
} else if (arg === 'string') {
|
||||||
|
bench.start();
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
|
result = new ClientRequest(data[i], { createConnection: noop });
|
||||||
|
}
|
||||||
|
bench.end(len);
|
||||||
|
} else {
|
||||||
|
throw new Error(`Unknown arg type ${arg}`);
|
||||||
}
|
}
|
||||||
bench.end(n);
|
require('assert').ok(result);
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,9 @@ runBenchmark('http',
|
|||||||
[
|
[
|
||||||
'benchmarker=test-double-http',
|
'benchmarker=test-double-http',
|
||||||
'c=1',
|
'c=1',
|
||||||
|
'e=0',
|
||||||
|
'url=long',
|
||||||
|
'arg=string',
|
||||||
'chunkedEnc=true',
|
'chunkedEnc=true',
|
||||||
'chunks=0',
|
'chunks=0',
|
||||||
'dur=0.1',
|
'dur=0.1',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user